In this step, you will install the OpenSSH server package, which allows your system to accept incoming SSH connections. SSH, or Secure Shell, is a cryptographic network protocol for operating network services securely over an unsecured network. The openssh-server package contains the core components for hosting an SSH server.
First, it's a good practice to update your system's package list to ensure you get the latest version of the software. The labex user has sudo privileges, which are required for system-wide package management.
Run the following command to update the package index:
sudo apt-get update
You will see output similar to the following, indicating that the package lists are being fetched from the repositories:
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
Get:3 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
...
Fetched 1,845 kB in 2s (1,040 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up-to-date.
Now, you can install the openssh-server package using apt-get. The -y flag automatically answers "yes" to any prompts, making the installation non-interactive.
sudo apt-get install -y openssh-server
After the command completes, you should see output confirming the installation and setup of the openssh-server and its dependencies:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
ncurses-term openssh-sftp-server ssh-import-id
...
Setting up openssh-server (1:8.9p1-3ubuntu0.1) ...
...
Creating SSH2 ECDSA key; this may take some time ...
Creating SSH2 ED25519 key; this may take some time ...
...
The OpenSSH server service, named sshd, should start automatically after installation. You can verify its status using the systemctl command, which is a tool for controlling the systemd system and service manager.
Check the status of the SSH service:
sudo systemctl status ssh
The output should show that the service is active (running). This confirms that the SSH server is ready to accept connections.
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2023-10-30 10:30:00 UTC; 5s ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 1234 (sshd)
Tasks: 1 (limit: 4617)
Memory: 1.2M
CPU: 8ms
CGroup: /system.slice/ssh.service
└─1234 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
...
Press the q key on your keyboard to exit the status view and return to the command prompt.
Great! The OpenSSH server is now installed and running on your system. In the next step, you will create a new user for SSH demonstration, then learn how to find the server's IP address and connect to it.