-->

Linux System Administrator Cheat Sheet


Hello Legendary people! welcome In this article, I will talk about some commands used in Linux operating systems. These commands can be used by Linux system administrators, as well as those interested in cybersecurity. 

I tried to make it easier for you by collecting these commands under certain headings. But I would like to warn you about one thing. Not all of the commands here will work on a single Linux distribution. It is natural that it will differ depending on the Linux distribution you are using.



The topics I have collected for you are as follows:

  1. SYSTEM INFORMATION
  2. HARDWARE INFORMATION
  3. PERFORMANCE MONITORING AND STATISTICS
  4. USER INFORMATION AND MANAGEMENT
  5. FILE AND DIRECTORY COMMANDS
  6. PROCESS MANAGEMENT
  7. FILE PERMISSIONS
  8. NETWORK INFORMATION
  9. ARCHIVES (TAR FILES)
  10. INSTALLING PACKAGES
  11. SEARCH
  12. SSH LOGINS
  13. FILE TRANSFERS
  14. DISC USE
  15. DIRECTORY NAVIGATION

1 – SYSTEM INFORMATION

# View Linux system information
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

uname -a
# To view kernel version information
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

uname -r
# To view the version of the Redhat distribution
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

cat /etc/redhat-release
# If you want to see how long the system has been running
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

uptime
# If you want to view the hostname of the system
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

hostname
# If you want to view the host's IP address
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

hostname -I
# To view the system reboot history
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

last reboot
# To display the current date and time
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

date
# Show the calendar of the current month
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

steal
# To view who is online in the system
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

w
# To view who you are logged in as
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

whoami
# Command to use to set an environment variable
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

export
# Icon that will appear in the terminal if you are a normal user
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

'$'
# Icon that will appear in the terminal if you are a root user
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

'#'

2 – HARDWARE INFORMATION

# To view kernel messages
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

dmesg
# To view CPU information
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

cat /proc/cpuinfo
# To view RAM information
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

cat /proc/meminfo
# View free and used memory (-h for human-readable format, -m for MB, -g for GB.)
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

free -h
# To view USB devices
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

lsusb -tv
# View DMI / SMBIOS (hardware information) from BIOS
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

dmidecode
# To view information about SDA Disk
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

hdparm -i /dev/sda
# To perform a read speed test on the SDA Disk
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

hdparm -tT /dev/sda
# To test unreadable blocks on SDA Disk
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

badblocks -s /dev/sda

3 – PERFORMANCE MONITORING AND STATISTICS

# To view the most important processes
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

ball
# To view statistics about the processor
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

mpstat 1
# To view virtual memory statistics
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

vmstat 1
# To view I/O statistics
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

iostat 1
# To view the last 100 syslog messages (For Debian-based systems, use /var/log/syslog.)
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

tail 100 /var/log/messages
# to capture and display all packets in the eth0 interface
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

tcpdump -i eth0
# To monitor all traffic on port 80 ( HTTP )
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

tcpdump -i eth0 'port 80'
# To list all open files on the system
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

lsof
# To list the files opened by the user
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

lsof -u <username>
# To display free and used memory(RAM) (-h for human readable format, -m for MB, -g for GB.)
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

free -h
# to show periodic updates
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

watch df -h

4 – USER INFORMATION AND MANAGEMENT

# To view the user and group IDs of your current user
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

ID
# To view the end users logged into the system
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

last
# To create a new group
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

groupadd <group name>
# Create an account named john with the value "John Smith" comment(comment) and create the user's home directory.
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

useradd -c "John Smith" -m john
# To delete user account
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

userdel <username>
# To add a user to a group
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

usermod -aG <group name> <username>

5 – FILE AND DIRECTORY COMMANDS

# To list all files in long list (detailed) format
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

ls -get
# View current working directory
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

pwd
# To create a new directory
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

mkdir <directory name>
# To delete file
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

rm <filename>
# To forcefully remove the file without asking for confirmation
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

rm -f <filename>
# To forcibly remove the directory recursively
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

rm -rf <directory name>
# copy file1 to file2
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

cp file1 file2
# To create an empty file
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

touch <filename>
# To create the contents of the file
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

cat <filename>
# To browse the text file briefly
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

less <filename>
# To display the first 10 lines of the file
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

head <filename>
# To view the last 10 lines of the file
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

tail <filename>
# To view the last 10 lines of the file and follow as new lines are added to the file
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

tail -f file
# to list the history of previous commands
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

history
# To reboot the machine
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

reboot

6 – PROCESS MANAGEMENT

# To view currently running processes
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

ps aux
# To view all currently running processes on the system
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

ps -ef
# To view process information for any process
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

ps -ef | grep <process name>
# Terminate a process based on its pid value
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

kill <pid value>
# To terminate a process by name
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

killall <process name>
# To show stopped or background running jobs
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

bg
# To view current running processes as a tree
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

pstree

7 – FILE PERMISSIONS

binhacks
PERMISSION EXAMPLE

         U G W
        rwx rwx rwx chmod 777 <filename>
        rwx rwx rx chmod 775 <filename>
        rwx rx rx chmod 755 <filename>
        rw- rw- r-- chmod 664 <filename>
        rw- r-- r-- chmod 644 <filename>

# NOTE: Try to use 777 permission as little as possible!

        LEGEND
        U = User
        G = Group
        W = World

        r = Read
        w = write
        x = execute
        - = no access

8 – NETWORK INFORMATION

# To view all network interfaces and ip address
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

ifconfig -a
# To show eth0's IP address and details
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

ifconfig eth0
# To set the network submask value
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

netmask
# To enter new records in the routing table
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

route
# To query or check network driver and hardware settings
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

ethtool eth0
# To send ICMP echo packets
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

ping <host IP>
# To make a whois query of the IP address you will query
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

whois <domain IP Address>
# To view the DNS information of the IP address you will query
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

dig <domain IP Address>
# Reverse lookup of IP_ADDRESS
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

dig -x IP_ADDRESS
# to view tcp and udp ports and related programs
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

netstat -nutlp

9 – ARCHIVES (TAR FILES)

To create a tar file named "archive.tar" containing the # directory
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

tar cf archive.tar <directory name>
# To extract the .tar file
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

tar xf <filename with tar extension>

10 – INSTALLING PACKAGES

# To search for a package by keyword
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

yum search <keyword>
# To install a package
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

yum install <package name>
# To view description and summary information about the package
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

yum info <package name>
# To remove the package
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

yum remove <package name>

# To search for a word in the file
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

grep <search word> <filename>
# To search for a word in the index
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

grep -r <word to search> <directory name>
# To find files and directories
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

locate <filename>
# To find files starting with "example" in "/home/john" directory
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

find /home/john -name 'example*'

12 – SSH LOGIN

# To establish ssh connection with username
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

ssh <host>
# To connect to the system as a user via ssh connection
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

ssh user@host
# To establish an ssh connection using a private port
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

ssh -p port user@host
# to generate public/private key pair
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

ssh-keygen

13 – FILE TRANSFERS

# to copy file.txt safely to the /tmp folder on the server
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

scp file.txt server:/tmp

14 – DISC USE

# To view free space in the file system
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

df -h
# To view disk partitions
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

fdisk -l
# To view disk usage for all files and directories in readable format
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

du-ah
# To show the total disk usage in the current directory
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

du -sh

15 – DIRECTORY NAVIGATION

# To move up one level from the directory
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

cd..
# To go to the $HOME directory
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

CD
# System-wide configuration files located here
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

/etc
# User account information is located here
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

/etc/passwd
# Where passwords are actually kept
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

/etc/shadow
# Where syslog records are kept
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

/etc/syslog.conf
# Where log files are kept 
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

/var/log
# Where the host is configured
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

/etc/hosts
# Where network information is kept
---------------------------------------------------------------- ---------------------------------------------------------------- --------------------------------------

/etc/networks

I have tried to cover as many points as possible in this section. Actually, we seem to have introduced some Linux commands, but they are all commands that the Linux system administrator should master. I hope it has been of use to you.

                               👏

Thank you to everyone who has already taken the time to read this. I'll see you in my next blog post.✅