Skip to main content

RHCE Certification Course

Chapter 26: How to Manage SSH, Cron Jobs, Services, and More [Bonus]

In this bonus chapter, you'll learn important Linux admin skills like remote access, service control, automation, and troubleshooting for RHCE preparation.

This bonus chapter covers extra Linux administration skills that are super helpful for anyone preparing for the RHCE exam.

These are important tools and tasks you might not use every day, but theyโ€™ll make your job much easier when managing real systems.

Whether you're using Ansible or working directly on servers, these skills will give you more control and confidence.

Letโ€™s take a quick look at each one.

SSH and Remote Access

Secure Shell, or SSH, is the standard and most secure way to log into remote systems in a Linux environment, which provides encrypted communication between your local machine and the remote server, ensuring that any sensitive data such as login credentials stays protected from prying eyes.

To initiate a remote connection, you simply use the ssh command followed by the username and the IP address or hostname of the target system, for example:

ssh user@remote_host

If itโ€™s your first time connecting, SSH will prompt you to confirm the server's identity, after which it will ask for the user's password.

The SSH server configuration is handled through the /etc/ssh/sshd_config file. Within this file, you can customize various security settings, such as disabling root login or changing the default SSH port from 22 to something less predictable, both of which are common best practices to reduce brute-force attack risks.

Once any changes are made to the SSH configuration, they wonโ€™t take effect until the SSH service is restarted.

sudo systemctl restart sshd

For improved security and convenience, especially when managing multiple servers, SSH key-based authentication is recommended.

To set this up, you first generate a key pair on your local machine using the ssh-keygen command.

ssh-keygen

Once the key is generated, you can copy the public key to the remote system using the command.

ssh-copy-id user@remote_host

After that, youโ€™ll be able to log in without entering your password every time, making the login process faster and more secure.

Scheduling Tasks in Linux

Automating tasks on Linux is crucial for regular maintenance, backups, and routine jobs. There are a few different tools available, each suited for different types of tasks.

The most commonly used tool is cron, which is perfect for scheduling repetitive tasks that run on a daily, weekly, or monthly basis.

You can edit your crontab (cron table) using the following command, which will opens a configuration file where you can define your tasks.

crontab -e

For example, to run a script every day at 2 AM, you would add the following line:

0 2 * * * /home/user/myscript.sh

Each field in the cron schedule represents the minute, hour, day of the month, month, and day of the week.

For one-time jobs, Linux provides a handy command called at. It allows you to schedule a task to run once at a specific time in the future.

For instance, if you want to run a backup script 5 minutes from now, you can use:

echo "/home/user/backup.sh" | at now + 5 minutes

Another more advanced method is to use systemd timers, which are modern, flexible, and event-driven alternatives to cron.

With systemd, you create two files: a .service file to define what should run, and a corresponding .timer file that schedules when it runs.

After creating both files, you enable the timer using systemctl to start the scheduled automation. This is especially useful in systems that rely heavily on systemd for service management.

Each of these tools has its use case, and depending on your needs, you can mix and match them for maximum flexibility in your automation setup.

Archiving, Compression, and File Transfer

Backing up and transferring files are everyday tasks for any Linux administrator. Thankfully, Linux offers powerful tools to get the job done quickly and efficiently.

To archive and compress files or directories, the tar command is your go-to tool. You can create a compressed .tar.gz archive using the following command:

tar -czvf backup.tar.gz /path/to/files

Here, -c creates the archive, -z compresses it using gzip, -v shows the progress (verbose), and -f specifies the filename.

If you need to extract the archive later, just run:

tar -xzvf backup.tar.gz

When it comes to syncing files or creating backups between systems, rsync is a lifesaver. Itโ€™s efficient and only transfers changes instead of re-copying everything.

A basic example looks like this: