Cloud Engineering Blog : AWS, Azure, Google, Linux/Unix, Windows, Open Source Technologies
Come and learn the Cloud
Linux/Ubuntu Common Operations Command Cheat Sheet
It’s been a long time that I have posted a blog on my site. It is my family, kids, and work that was kept me busy all these years.
In recent weeks, I was working with a few newbies and giving a few tasks on Linux/Cloud platform side, like deploying a sample LAMP Stack, WordPress Stack, Docker tasks, etc. But they are often coming back and asking, unable to SSH to the instances, unable to install the packages(mainly in LAMP). I should keep asking them which Linux Distro you are running and then was able to help them with the right approach. They are confusing between different Linux Distros and failing to understand what commands should be used in which distro of Linux, and spending a tiresome amount of time to search in google.
That’s where I decided to put together common operations commands cheat sheet for a quick reference for all the newbies for the current Standard Linux Distros which are highly using in the market – Redhat Linux, Ubuntu, and Amazon Linux2 . If you feel you have already seen such kind of blog post, please ignore this and move on. Otherwise, if it provides a little help to your regular Linux Operations work, then the goal is achieved.
Category | Operations | Redhat Enterprise Linux 7.8 | Redhat Enterprise Linux 8.2 | Ubuntu 18.04 LTS | Ubuntu 20.04 LTS | Amazon Linux 2 | ||
System Information | OS Version & Distribution | cat /etc/*release* | cat /etc/*release* | cat /etc/*release* | cat /etc/*release* | cat /etc/*release* | ||
Kernel Version | uname -r | uname -r | uname -r | uname -r | uname -r | |||
Services Management | Services Management Command | systemctl | systemctl | systemctl | systemctl | systemctl | ||
Services Start/Stop/Status | systemctl <stop/start/restart/status> <servicename> | systemctl <stop/start/restart/status> <servicename> | systemctl <stop/start/restart/status> <servicename> | systemctl <stop/start/restart/status> <servicename> | systemctl <stop/start/restart/status> <servicename> | |||
Service AutoStart (upon reboot) | systemctl enable <servicename> | systemctl enable <servicename> | systemctl enable <servicename> | systemctl enable <servicename> | systemctl enable <servicename> | |||
Service Disablement(Cannot be restarted using systemctl start/restart) | systemctl mask <servicename> | systemctl mask <servicename> | systemctl mask <servicename> | systemctl mask <servicename> | systemctl mask <servicename> | |||
Firewall/Security Service | Firewall ServiceName | firewalld | firewalld | ufw | ufw | firewalld (by default, package may not have been installed) | ||
Selinux Status | sestatus | sestatus | sestatus | sestatus | sestatus | |||
Selinux Protected Servics Config | cat /etc/sestatus.conf | cat /etc/sestatus.conf | cat /etc/sestatus.conf | cat /etc/sestatus.conf | cat /etc/sestatus.conf | |||
Selinux Config Change | cat /etc/selinux/config | cat /etc/selinux/config | cat /etc/selinux/config | cat /etc/selinux/config | cat /etc/selinux/config | |||
Package Management | Packages Installation | yum install <package name> | yum install <package name> | apt insall <package name> | apt insall <package name> | yum install <package name> | ||
Packages Search from repos | yum search <package name> | yum search <package name> | apt search <package name> | apt search <package name> | yum search <package name> | |||
Querying Instaled packages | rpm -qa | grep <package name> | rpm -qa | grep <package name> | dpkg -l | grep <package name> | dpkg -l | grep <package name> | rpm -qa | grep <package name> | |||
OS/Package Update | OS/Package Update | yum update = updates the installed packages to the latest versions, if available yum upgrade = updates the installed packages to the latest versions, and deletes the obsolete packages, The removal of obsolete packages can be risky, as it may remove packages that you use |
yum update = updates the installed packages to the latest versions, if available yum upgrade = updates the installed packages to the latest versions, and deletes the obsolete packages, The removal of obsolete packages can be risky, as it may remove packages that you use |
apt update = updates the local cache with the the list of available packages and their versions, but it does not install or upgrade any packages apt upgrade = updates the installed packages to the latest versions, if available |
apt update = updates the local cache with the the list of available packages and their versions, but it does not install or upgrade any packages apt upgrade = updates the installed packages to the latest versions, if available |
yum update = updates the installed packages to the latest versions, if available yum upgrade = updates the installed packages to the latest versions, and deletes the obsolete packages, The removal of obsolete packages can be risky, as it may remove packages that you use |
||
Network/IP Address | Display IP Address | ifconfig(not available by default in Centos7) ip address |
ifconfig ip address |
ifconfig ip address |
ifconfig ip address |
ifconfig ip address |
||
Network Service Name | network | NetworkManager | NetworkManager | NetworkManager | network | |||
Network Settings Definition(eth0) | cat /etc/sysconfig/network-scripts/ifcfg-eth0 | cat /etc/sysconfig/network-scripts/ifcfg-eth0 | cat /etc/network/interfaces | cat /etc/network/interfaces | cat /etc/sysconfig/network-scripts/ifcfg-eth0 | |||
Remote SSH Connectivity | Not able to connect to SSH(this steps not applicable in public cloud machines) | i. Make sure IPAddres is assigned to eth0, if not : cat /etc/sysconfig/network-scripts/ifcfg-eth0 – change the “ONBOOT=no” to “ONBOOT=yes” ii.Check if the SSH Server installed, if not install it : yum install openssh-server iii. Stop the firewall: systemctl stop firewalld iv. Disable Selinux: /etc/selinux/config v. Reboot the instance |
i. Make sure IPAddres is assigned to eth0, if not : cat /etc/sysconfig/network-scripts/ifcfg-eth0 – change the “ONBOOT=no” to “ONBOOT=yes” ii.Check if the SSH Server installed, if not install it : yum install openssh-server iii. Stop the firewall: systemctl stop firewalld iv. Disable Selinux: /etc/selinux/config v. Reboot the instance |
i.Check if the SSH Server installed, if not install it : yum install openssh-server ii. Stop the firewall: systemctl stop ufw iii. Reboot the instance |
i.Check if the SSH Server installed, if not install it : yum install openssh-server ii. Stop the firewall: systemctl stop ufw iii. Reboot the instance |
N/A | ||
LAMP Stack Installation | Apache Packages | yum install httpd (default version : 2.4) | yum install httpd (default version : 2.4) | apt install apache2 (default version : 2.4) | apt install apache2 (default version : 2.4) | yum install httpd (default version : 2.4) | ||
PHP Packages | The default version is 5.4, to install 7.2.X follow the below steps: yum install epel-release yum install yum-utils –y yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm yum-config-manager –enable remi-php72 yum install php |
yum install php (default version : 7.2) | apt install php | apt install php | yum update –y amazon-linux-extras install -y php7.2 |
|||
Apache PHP Module | The Apache/PHP module will be installed automatically if we install httpd and php packages one after the other ls /etc/httpd/conf.d – look for php.conf file |
The Apache/PHP module will be installed automatically if we install httpd and php packages one after the other ls /etc/httpd/conf.d – look for php.conf file |
The Apache/PHP module will be installed automatically if we install httpd and php packages one after the other ls /etc/apache2/mods-enabled – look for php7.2.conf file |
The Apache/PHP module will be installed automatically if we install httpd and php packages one after the other ls /etc/apache2/mods-enabled – look for php7.2.conf file |
The Apache/PHP module will be installed automatically if we install httpd and php packages one after the other ls /etc/apache2/mods-enabled – look for php7.2.conf file |
|||
MySQL Server | The default version is 5.7, to install the 8.0.X follow the below steps:
i. rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm ii. sed -i ‘s/enabled=1/enabled=0/’ /etc/yum.repos.d/mysql-community.repo iii. yum –enablerepo=mysql80-community install mysql-community-server |
yum install mysql-server.x86_64 | The default version is 5.7, to install the 8.0.X follow the below steps:
i. wget -c https://repo.mysql.com//mysql-apt-config_0.8.13-1_all.deb ii. dpkg -i mysql-apt-config_0.8.13-1_all.deb (choose “OK” on the TUI prompt) iii. apt update iv. apt-get install mysql-server |
apt-get install mysql-server | The default version is 5.7, to install the 8.0.X follow the below steps:
i. rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm ii. sed -i ‘s/enabled=1/enabled=0/’ /etc/yum.repos.d/mysql-community.repo iii. yum –enablerepo=mysql80-community install mysql-community-server |
|||
MySQL PHP Module | yum -y install php-mysqlnd php-pdo | yum -y install php-mysqlnd php-pdo | apt install php7.2-mysql/bionic-updates | apt install php7.4-mysql/focal | N/A (The amazon linux extras php7.2 command will install the php-mysql plugin too, refer the php installation row) | |||
Apache/PHP Test | i. Create a file called info.php under the /var/www/html directory, with the below lines: <?php phpinfo(); ?> ii. Restart the http service : systemctl restart httpd iii. Browse the info.php file – http://ipaddress/info.php |
i. Create a file called info.php under the /var/www/html directory, with the below lines: <?php phpinfo(); ?> ii. Restart the http service : systemctl restart httpd iii. Browse the info.php file – http://ipaddress/info.php |
i. Create a file called info.php under the /var/www/html directory, with the below lines: <?php phpinfo(); ?> ii. Restart the http service : systemctl restart apache2 iii. Browse the info.php file – http://ipaddress/info.php |
i. Create a file called info.php under the /var/www/html directory, with the below lines: <?php phpinfo(); ?> ii. Restart the http service : systemctl restart apache2 iii. Browse the info.php file – http://ipaddress/info.php |
i. Create a file called info.php under the /var/www/html directory, with the below lines: <?php phpinfo(); ?> ii. Restart the http service : systemctl restart apache2 iii. Browse the info.php file – http://ipaddress/info.php |