How to Install SSH Server on Ubuntu 22.04
SSH Server is a server-side software program that uses a secure shell to accept the connections from the client system. It is an alternative for Telnet and other protocols such as rlogin, rsh, etc.
SSH server is not installed on Ubuntu 22.04 by default. However, you may want to enable it after the fresh installation of the OS for connecting your Ubuntu system from external machines.
To install the SSH server and enable it on Ubuntu 22.04, you need to log in as a root user or a user with sudo privileges to execute commands in the next section.
Install SSH Server on Ubuntu 22.04
Open up a terminal and then execute the below command to update the repository index.
sudo apt update
Then, install the SSH Server package using the
sudo apt install -y openssh-server
Enable SSH Server on Ubuntu 22.04
By now, the SSH server service should start automatically. You can verify the SSH server service status by running the following command.
sudo systemctl status ssh
The above screenshot confirms that the SSH service is up and running.
Allow SSH in Firewall
Sometimes, you may need to allow SSH connections coming from client systems in the firewall. So, use the below command to create a rule for allowing SSH connections from external machines.
sudo ufw allow ssh sudo ufw enable sudo ufw reload
Access Ubuntu 22.04 via SSH
You can connect to your system via SSH using putty from Windows or built-in SSH clients from Linux or macOS.
Enable SSH Root Login on Ubuntu 22.04
By default, you will not be able to log in as the root user via SSH for security reasons. However, you can enable root login by editing the SSH configuration file at your own RISK.
Update the SSH configuration with the below command.
echo "PermitRootLogin Yes" | sudo tee -a /etc/ssh/sshd_config
Then, restart the SSH service to read the new configuration.
sudo systemctl restart ssh
Now, you should be able to login directly as the root via ssh.
Disable SSH Service on Ubuntu 22.04
If you want to disable SSH on your system, you can stop and disable the SSH service so that it doesn’t start on a system reboot.
sudo systemctl stop ssh sudo systemctl disable ssh
That’s All. I hope you have learned how to install SSH Server on Ubuntu 22.04. You can now perform management activities over the terminal. Additionally, you can set up SSH Key-based authentication that lets you log in to your system without entering a password.