RedHat offers numerous commands that can be used across many Linux distributions and they can make life easier for you as a system adminsitrator, or a home PC user. If you’re just getting started with RedHat Enterprise Linux, then these commands can help you to get up to speed sooner!
I cannot guarantee that the commands in this article will work in all versions of RedHat.
Also bear in mind that the structure of commands can change over time. I tested the following commands on RedHat Enterprise Linux 8.0. I include short examples of the Linux commands and may include a brief comment here and there to clarify them.
Before continuing, if you get a ‘permission denied‘ error, it is because you don’t have permission to do something. In that case, you may need to prefix ‘sudo’ before your command.
|Table Of Contents|
|View Logs/Edit Config Files.|
|Install or remove Software via the Command Line.|
Viewing RedHat Logs And Editing/Displaying Configuration Files
less: If you need to view the contents of a log file at the command line in RedHat, you can use the ‘less‘ command. The ‘less’ command accepts the log filename as a parameter and then you can scroll through it using the ‘page down‘ key. You may need to prefix the command with ‘sudo‘ if you are a non-root user.
Another example is:
The examples above view the dnf (package management utility) and the operating system’s boot logs respectively.
tail: You can view the tail end of log files in RedHat using the ‘tail‘ command. This is useful because you can leave it running and monitor the current status of the respective program’s log file to see errors manifest themselves in real time/as they occur.
An example of the ‘tail’ command’s usage is:
tail -f /var/log/apache2/error.log
nano: Nano is a text editor. However, the fact that it is a command line text editor makes it terribly convenient for editing configuration files on servers that have no GUI, or if you are editing them remotely via SSH. You simply type the following and it opens the file for editing:
After that, you can just use the arrow keys to navigate your way through the file and make the necessary changes. To find a particular part of a config file to edit, you can press Ctrl + W and then type in a portion of what you’re searching for and press enter. For example: ‘post_max_size‘ in the ‘php.ini’ file. Press Ctrl + O to save your changes and then press Ctrl + X to exit Nano.
echo: You can use the echo command to write a line to a file using the following command (it will overwrite the contents of the file):
echo "Test line" > filename.txt
Installing Software Via Command Line In RedHat
dnf: You can use the dnf package manager to install or remove RedHat packages (programs) using the following commands:
dnf install programname
dnf remove programname
If the desired package is not in the RedHat repositories, you may have to download the .rpm file and then install it using the ‘rpm’ command. For example, I had to do that with NASM (Netwide Assembler):
Bonus: Use wget to download the rpm package!
It is also possible that your package is in the RedHat repositories but is under a different name, maybe one that includes the package version. For example: programname-1.0. To confirm this, you can use the ‘dnf search’ command and then type out the full package name when using the install command.
Bear in mind that the ‘dnf remove’ command may remove other packages as well. It will tell you which ones.
RedHat Permissions, Authentication, And User Account Control
su: You can switch to another user or login to another user account on RedHat using the ‘su’ command (requires root privileges):
useradd: You can add a user using the ‘useradd’ command.
passwd: You can change a user’s password using the ‘passwd’ command.
userdel: Delete a user.
List RedHat users:
Generate A Random Password
gpg: You can use GnuPG to generate random passwords if you wish using the following command (I wish I could remember it too):
gpg --gen-random --armor 1 10
openssl: OpenSSL is another command line tool that makes it easy to generate secure passwords:
openssl rand -base64 16
Clear scrollback after entering passwords or keys in the terminal (otherwise people can just press the up arrow key and see what you typed):
ssh: You can use the Secure Shell (SSH) to connect to your server via an SSH tunnel with this refreshingly short command:
It will ask you to enter your password, unless you configured it to use another mode of authentication. You can also replace ‘domain.com’ with the server IP address if it doesn’t have a domain.
chmod: You can change file permissions in RedHat with the ‘chmod’ command. You can use it to assign read, write, or execute permissions to a file. Here are a few examples.
Create a test file then execute them all from the top down to see what happens. The ‘ls -l filename.txt’ command shows you the current permissions.
+x permits execution, -x revokes the execution permission.
+w provides the write permission, and -w revokes the write permission.
chmod +x filename.txt ls -l filename.txt chmod -x filename.txt ls -l filename.txt chmod +w filename.txt ls -l filename.txt chmod -w filename.txt ls -l filename.txt
chown: This assigns ownership of a file to a user using a measly 3-word command (root privileges required). Example:
chown newowner filename.txt
Run the ‘ls -l filename.txt’ command, and you should see the new user’s name to the right.
users: The ‘users’ command will list the users that are currently logged in to RedHat.
Networking Commands In RedHat
ifconfig: The ‘ifconfig’ command can tell you about your current RedHat network connections including, but not limited to your Wi-Fi network, LAN, or loopback interface.
The output will look something like this:
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255 inet6 fe80::2af6:870f:8f78:73d4 prefixlen 64 scopeid 0x20 ether 08:00:27:28:14:f5 txqueuelen 1000 (Ethernet) RX packets 12461 bytes 17036134 (16.2 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3116 bytes 544555 (531.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:88:30:fe txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ifup: Start up a network interface in RedHat, such as your Wi-Fi adapter or your LAN NIC. For example, let us start up the interface enp0s3:
ifdown: Shut down a network interface in RedHat, such as your Ethernet NIC or Wi-Fi adapter. For example, let’s shut down ‘enp0s3’:
traceroute: This traces the path that a packet takes to reach its destination. Usage:
top: View running processes in RedHat as well as their system resource usage (CPU usage, RAM usage, among other details).
You must log in to post a comment.