SSH Secure Shell
Secure Shell (“SSH”) is one of the most common utilities when access to a remote device is needed. It’s encrypted, powerful, and simple to understand.
SSH overview
SSH uses a client/server model where one computer acts as an SSH server[^1] and allows other computers to connect.
Connecting to an SSH Server
To access a device remotely, the ssh
command is run from the shell, mostly used with this format:
ssh [username@]<server url>
If you don’t specify a username then SSH will attempt to connect you using the username with which you are logged in. Here are some examples:
ssh [email protected]
- This will attempt to connect to the server at myserver.com using the username myuser
ssh [email protected]
- This is just like the example above except you can also specify an IP address instead of a hostname
ssh myserver.com
- This will attempt to connect to the SSH server at myserver.com using your current username
When using any of the above commands, once connected to the remote server you’ll be prompted for a password.
Running Your Own SSH Server
Most modern Linux distros come with the required software to host your own SSH server. To allow users to connect to your machine, start the SSH server application using
sudo systemctl start sshd
Note that the above command uses sudo
. The sudo
command will execute the following commands as root (the superuser). For many commands that involve starting and stopping servers, the permission of the system’s superuser is necessary. You can read more about the sudo
command here. The above command also uses the systemctl
command. This command is mostly used to manage servers or other Linux services.
Once the above command is run, your machine will begin listening for incoming connections on port 22. You can verify that the SSH server application started correctly by using the command
systemctl status sshd
You should see output similar to this:
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: enabled)
Drop-In: /usr/lib/systemd/system/service.d
└─10-timeout-abort.conf
Active: active (running) since Sun 2024-04-07 14:00:20 EDT; 44min ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 1065 (sshd)
Tasks: 1 (limit: 4396)
Memory: 156.0K
CPU: 50ms
CGroup: /system.slice/sshd.service
└─1065 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
Apr 07 14:00:20 ultramarine systemd[1]: Starting sshd.service - OpenSSH server daemon...
Apr 07 14:00:20 ultramarine sshd[1065]: Server listening on 0.0.0.0 port 22.
Apr 07 14:00:20 ultramarine sshd[1065]: Server listening on :: port 22.
Apr 07 14:00:20 ultramarine systemd[1]: Started sshd.service - OpenSSH server daemon.
Check for the field that says Active: active (running)
to ensure that the SSH server is listening for incoming connections.
If you’d like to stop the SSH server, you can do so with
sudo systemctl stop sshd
You should see output similar to this:
○ sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: enabled)
Drop-In: /usr/lib/systemd/system/service.d
└─10-timeout-abort.conf
Active: inactive (dead) since Sun 2024-04-07 14:50:24 EDT; 3s ago
Duration: 50min 4.206s
Docs: man:sshd(8)
man:sshd_config(5)
Process: 1065 ExecStart=/usr/sbin/sshd -D $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 1065 (code=exited, status=0/SUCCESS)
CPU: 58ms
Apr 07 14:50:24 ultramarine systemd[1]: Stopping sshd.service - OpenSSH server daemon...
Apr 07 14:50:24 ultramarine sshd[1065]: Received signal 15; terminating.
Apr 07 14:50:24 ultramarine systemd[1]: sshd.service: Deactivated successfully.
Apr 07 14:50:24 ultramarine systemd[1]: Stopped sshd.service - OpenSSH server daemon.
← Back To: Software and Package Management
[^1]### A Note about the Word “Server” It’s common to hear the word “server” used but not understand exactly what is meant. Here are a couple examples of how “server” can be used:
- It can refer to a physical machine somewhere
- Ex: Our email server lost power over the weekend.
- It can refer to a specific application running on one machine (or even a number of machines across the world!)
- Ex: The SSH server is up so that users can connect.
In this guide we’ll try to make it clear to which we’re referring.