Linux Mastery

The Human Knowledge Project


Chapter 18 — SSH & Remote Systems


Why This Chapter Matters

One of Linux's greatest strengths is remote administration.

Linux systems can be managed from:

Administrators routinely maintain systems without physically touching them.

This is possible because Linux was designed from the beginning as a multi-user, networked operating system.

The primary technology that makes secure remote administration possible is:


SSH

Understanding SSH is an essential step toward becoming an effective Linux user or administrator.


Learning Objectives

Upon completing this chapter, you will be able to:


Introduction

Imagine sitting at your computer in Washington while managing a Linux server in New York.

Or administering a cloud server located on another continent.

To Linux, distance makes very little difference.

Once a secure connection has been established, the remote computer behaves almost as though you were sitting directly in front of it.

This ability has made Linux the operating system of choice for servers, cloud infrastructure, research laboratories, universities, and businesses around the world.


1. What Is SSH?

SSH stands for:


Secure Shell

SSH creates an encrypted connection between two computers.

It allows users to:

SSH has become the standard method for securely managing Linux systems across networks.

THKI Memory Aid


Your Computer
        │
Encrypted Connection
        │
Remote Linux System

SSH creates a secure communication channel between two computers.


2. Why SSH Matters

Before SSH became common, older remote-access protocols often transmitted passwords in plain text.

Anyone monitoring the network could potentially read those passwords.

SSH solves this problem by encrypting the entire communication session.

Encryption protects:

Today, SSH is one of the most important security technologies used by Linux administrators.


3. SSH Client and SSH Server

SSH consists of two cooperating components.

| Component | Purpose |

|-----------|---------|

| SSH Client | Initiates connections to remote systems |

| SSH Server (sshd) | Accepts incoming SSH connections |

The client starts the conversation.

The server listens for connection requests.

Both are required for successful remote administration.


4. The sshd Service

The SSH server process is usually named:


sshd

which stands for:


SSH daemon

The SSH daemon runs quietly in the background waiting for connection requests.

Without sshd, a Linux computer cannot accept incoming SSH connections.

Servers commonly leave sshd running continuously.


5. Checking the SSH Service

To determine whether the SSH service is running:


systemctl status ssh

On some Linux distributions the service is named:


systemctl status sshd

The output indicates whether the service is:

Checking service status is often the first troubleshooting step when SSH connections fail.


6. Starting the SSH Server

To start the SSH service immediately:


sudo systemctl start ssh

This launches the SSH daemon and allows remote systems to connect.

If the service is stopped again or the computer is rebooted, SSH will no longer accept connections unless it is configured to start automatically.


7. Starting SSH Automatically

To enable SSH each time Linux boots:


sudo systemctl enable ssh

This tells systemd to start the SSH service automatically during future system startups.

Remember:

THKI Memory Aid


start
      ↓
Run Now
enable
      ↓
Run Every Boot

8. Connecting to a Remote System

The basic SSH command is:


ssh username@hostname

Example:


ssh norm@192.168.1.50

After authentication, a secure shell opens on the remote computer.

Commands entered after the connection is established execute on the remote system rather than on the local computer.


9. What Happens During Login?

A typical SSH connection follows these steps:

  1. Connect to the remote host.
  2. Negotiate encryption.
  3. Authenticate the user.
  4. Launch the user's shell.
  5. Begin the remote session.

From this point forward, nearly everything typed into the terminal runs on the remote Linux system.

This makes SSH feel almost like sitting in front of the remote computer.


10. Remote Shell Prompt

After logging in, the command prompt usually changes.

Example:


norm@SERVER:~$

This reminds you that commands are now running on the remote machine.

When administering multiple systems, always pay attention to the prompt to avoid making changes on the wrong computer.


11. Ending an SSH Session

When you finish working on the remote system, disconnect using:


exit

or press:


Ctrl + D

The remote shell closes, and you return to the command prompt on your local computer.


12. Hostnames and IP Addresses

SSH can connect using either:

Examples:


ssh user@example.com

ssh user@192.168.1.20

Using hostnames is usually easier to remember, while IP addresses are useful for troubleshooting or when DNS is unavailable.


13. SSH Port 22

By default, SSH communicates using:


Port 22

Firewalls and routers must allow access to this port before remote SSH connections can be established.

Many administrators leave SSH on Port 22, while others choose a different port to reduce automated scanning attempts.



14. SSH Keys

Although SSH supports password authentication, many Linux administrators prefer using SSH keys.

SSH keys provide:

Large organizations often require SSH keys instead of passwords for administrative access.


15. Generating an SSH Key Pair

To create a new SSH key pair:


ssh-keygen

The program asks several questions, including where to store the keys and whether to protect the private key with a passphrase.

Pressing Enter accepts the default values.


16. Public and Private Keys

SSH key generation creates two related files.

| File | Purpose |

|------|---------|

| id_ed25519 (or id_rsa) | Private key |

| id_ed25519.pub (or id_rsa.pub) | Public key |

Modern Linux systems usually recommend the Ed25519 key type.

Older systems may still use RSA keys.

THKI Memory Aid


Private Key
       ↓
Keep Secret
Public Key
       ↓
Share Freely

Your private key should never be shared with anyone.

Your public key is intended to be copied to remote systems.


17. Why SSH Keys Matter

When using SSH keys, the remote computer verifies that your private key matches the public key it already trusts.

Because your private key never leaves your computer, authentication is both convenient and highly secure.

SSH keys also make automation possible because scripts can authenticate without repeatedly prompting for passwords.

THKI Insight

Many organizations disable password authentication entirely and require SSH keys for administrative access.

Keys are generally more secure and easier to automate than passwords.


18. Installing Your Public Key

To copy your public key to a remote Linux system:


ssh-copy-id user@remotehost

This installs your public key into the remote account.

Future SSH logins can then authenticate using your key pair instead of a password.


19. Known Hosts

The first time you connect to a remote system, SSH asks whether you trust that computer.

If you answer yes, SSH records information about the remote system in:


~/.ssh/known_hosts

During future connections, SSH compares the stored information with the remote host.

If something changes unexpectedly, SSH displays a warning.

This helps protect against impersonation attacks.


20. SSH Configuration Files

SSH behavior can be customized using configuration files.

Common files include:

| File | Purpose |

|------|---------|

| /etc/ssh/sshd_config | SSH server configuration |

| ~/.ssh/config | User SSH client configuration |

To examine the server configuration:


less /etc/ssh/sshd_config

After changing the server configuration, restart the SSH service:


sudo systemctl restart ssh

21. scp — Secure Copy

SSH can also transfer files securely.

The command used is:


scp

Copy a local file to a remote system:


scp file.txt user@remotehost:/home/user/

Copy a remote file back to your current directory:


scp user@remotehost:/home/user/file.txt .

The period (.) represents the current directory.


22. Copying Entire Directories

To copy an entire directory recursively:


scp -r project/ user@remotehost:/backup/

The -r option tells scp to copy all files and subdirectories.

THKI Memory Aid


Local Computer
        │
      scp
        │
Remote Computer

Remember:


23. rsync Over SSH

The rsync command can synchronize files through an SSH connection.

Example:


rsync -av project/ user@remotehost:/backup/project/

Unlike ordinary copying, rsync transfers only files that have changed.

Benefits include:

This makes rsync one of the most valuable tools for remote system administration.


24. Persistent Terminal Sessions

Long-running administrative work sometimes continues for hours.

If the network connection is interrupted, ordinary SSH sessions end immediately.

Linux provides tools that allow terminal sessions to continue running even after an SSH connection is lost.

Two of the most common are:


25. tmux

tmux stands for:


Terminal Multiplexer

Start a new session:


tmux

Detach from the session without stopping it:

Press:


Ctrl + B

then:


D

Reattach later:


tmux attach

Detached sessions continue running even after the SSH connection closes.

THKI Insight

Many experienced Linux administrators begin every SSH session by starting tmux.

If their network connection drops, their programs continue running on the remote system, allowing them to reconnect later without losing work.


26. screen

Another terminal multiplexer is:


screen

Start a session:


screen

Detach:


Ctrl + A

then:


D

Reconnect later:


screen -r

Although screen is older than tmux, both remain useful for remote administration.


27. tmux vs. screen

| Tool | Notes |

|------|-------|

| tmux | Modern, highly configurable, widely preferred |

| screen | Older, simpler, still widely available |

Both tools help preserve long-running remote sessions and reduce the risk of losing work due to network interruptions.



28. Real-World Remote Administration

Remote administration has transformed the way Linux systems are managed.

A single administrator can securely maintain hundreds—or even thousands—of computers located around the world.

Typical daily tasks include:

Most of this work happens without anyone physically touching the remote machine.


29. A Typical Administrative Workflow

A Linux administrator might perform the following steps:

Connect to the remote server:


ssh admin@server

Start a persistent session:


tmux

Monitor system logs:


tail -f /var/log/syslog

Restart a service if needed:


sudo systemctl restart ssh

Transfer updated configuration files:


scp config.conf admin@server:/etc/

Synchronize project files:


rsync -av project/ admin@server:/srv/project/

Detach from the tmux session before disconnecting.

The administrator can later reconnect and continue working exactly where they left off.


30. Why Remote Administration Matters

Without remote administration:

SSH is one of the technologies that makes modern computing possible.


31. SSH Security Best Practices

Because SSH often provides administrative access, protecting it is extremely important.

Good security practices include:

Following these practices greatly reduces the risk of unauthorized access.


32. Why Root Login Is Usually Disabled

Many Linux administrators disable direct remote login as the:


root

user.

Instead, they log in using a normal account and perform administrative tasks with:


sudo

This approach:

It also reinforces the Linux principle of least privilege.

THKI Insight

Good administrators spend most of their time as ordinary users.

They use sudo only when administrative privileges are actually required.


33. Safety Note

SSH is a powerful administrative tool.

Incorrect configuration can:

Always test configuration changes carefully before deploying them to production systems.

When possible, keep an existing SSH session open while testing changes so you can recover if something goes wrong.


Chapter Summary

| Command / Concept | Purpose |

|-------------------|---------|

| ssh | Secure remote login |

| sshd | SSH server daemon |

| ssh-keygen | Generate SSH key pairs |

| ssh-copy-id | Install a public key on a remote system |

| scp | Securely copy files |

| rsync | Efficient file synchronization |

| tmux | Persistent terminal sessions |

| screen | Terminal multiplexer |


Key Ideas

SSH is the standard method for securely administering Linux systems across networks.

Understanding:

provides the foundation for modern Linux system administration.

Whether managing a home server or a global cloud infrastructure, SSH is one of the most valuable tools in the Linux administrator's toolkit.


Practice Exercises

  1. Determine whether SSH is installed on your system.
  2. Check the SSH service status.
  3. Start the SSH service (if permitted).
  4. Enable SSH to start automatically during boot.
  5. Verify that SSH is listening on Port 22.
  6. Connect to another Linux system using SSH, if available.
  7. Connect to your own computer using:
  8. 
    ssh localhost
    

if the SSH server is running.

  1. Generate an SSH key pair using:
  2. 
    ssh-keygen
    
  3. Locate your public and private key files.
  4. Explain the difference between the public key and the private key.
  5. Install a public key on another Linux system using:
  6. 
    ssh-copy-id
    
  7. Copy a file using:
  8. 
    scp
    
  9. Copy an entire directory using:
  10. 
    scp -r
    
  11. Synchronize two directories using:
  12. 
    rsync -av
    
  13. Start a tmux session.
  14. Detach and reattach to the session.
  15. Repeat the exercise using screen, if installed.
  16. Explain why persistent sessions are valuable during remote administration.
  17. Describe a real-world situation where SSH would be essential.
  18. Explain why SSH keys are generally preferred over passwords.
  19. Explain why direct root login is often disabled.
  20. Describe a workflow involving:
  1. Explain how SSH demonstrates the Linux philosophy of small tools working together.

Looking Ahead

You now understand how Linux systems can be administered securely from almost anywhere in the world.

In the next chapter, you'll learn how Linux automates repetitive work using scheduled tasks, allowing maintenance jobs, backups, and other routine operations to run automatically—even when no one is logged in.