April 20, 2020
๐ I describe Shell with words omnipresence or has ubiquity. Quick filtering or command chaining is like magic and gives us more powers, with Pipe (โ|โ) and CLI utilities like sed, awk, grep, etc.
๐ Hence, if you are related to Linux and Server troubleshooting in any way, and that involves your day to day work. Here is some quick reference to command-line know-hows:
Note: This is Part 1, just a quick reference guide that Iโve had in my cheatsheet for server troubleshooting. The list I have is exhaustive, so I will keep things simple and continue to share insights in a phased-out manner.
---
ps | SSH | Removing files | Grep | Find | Sudo | SSL
---Quick reference: PS | SSH | Removing files | Grep | Find | Sudo | SSL
Print All Processes Running as Root
ps -U root -u rootShow process tree of all PIDs
ps auxwfShow all process info and hierarchy
ps -efHSort by the highest CPU utilization in ascending order
ps -aux --sort -pcpu | lessSort by the highest Memory utilization in ascending order
ps -aux --sort -pmem | lessFind top running processes by highest memory and CPU usage in Linux
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | heador
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | headSort by memory | CPU and display only the top ten of the result
ps -aux --sort -pcpu,+pmem | head -n 10Generate generic ssh key pair
ssh-keygen -q -t rsa -f ~/.ssh/<name> -N '' -C <name>Remove files over 30 days old
find . -mtime +30 | xargs rm -rfRemove files older than 7 day starting with โbackupโ
find . -type f -name "backup*" -mtime +7 -exec rm {} \;Look through all files in current dir for word โfooโ
grep -R "fooโ .View last ten lines of output
grep -i -C 10 "invalid view sourceโ /var/log/info.logDisplay line number of message
grep -n โpatternโ <file>Exclude directories in find
find /tmp -not \( -path /tmp/dir -prune \) -type p -o -type bTo check sudo access for a user!
Method 1:
sudo -l -U sachcode
User sachcode may run the following commands on host:(ALL) ALLMethod 2: Another way to find out if a user has sudo access is by checking if the said user is member of the sudo group.
groups sachcode
sachcode : sachcode wheel dockerMethod 3: list all sudo users of your system
genet group sudoWith curl's insecure option we can filter the output and get only the Server certificate information:
~ $ curl --insecure -v https://www.sachcode.com 2>&1 | \
> awk 'BEGIN { cert=0 } /^\* Server certificate:/ { cert=1 } \
> /^\*/ { if (cert) print }'
* Server certificate:* subject: CN=*.sachcode.com
* start date: Mar 22 04:34:05 2020 GMT
* expire date: Jun 20 04:34:05 2020 GMT
* common name: *.sachcode.com
* issuer: CN=Let's Encrypt Authority X3,O=Let's Encrypt,C=US
* Connection #0 to host www.sachcode.com left intact