How to Install OpenSSH Server on Ubuntu 18.04
In this tutorial we are going to install OpenSSH on Ubuntu 18.04. OpenSSH is most popular SSH server solution for Ubuntu Linux.
In Ubuntu 18.04 server, SSH server is an option during the installation process and your Ubuntu system probably has the OpenSSH server installed already. If you are not sure, run the following command to check whether you have SSH server installed already.
dpkg --get-selections | grep openssh
If you see openssh-server in the output, SSH server is installed already. Otherwise, you can install openssh-server package with following command:
apt-get update apt-get install openssh-server
After you’ve installed the openssh-server package, check the status of the ssh service with the systemctl command:
sudo systemctl status ssh.service
The status should be active (running), if not run following two commands to start and enable the ssh service:
sudo systemctl start ssh.service sudo systemctl enable ssh.service
You can also run the ss command to make sure that the Ubuntu system listen on TCP port 22.
ss -tulp | grep ssh
If the Ubuntu firewall is enabled, you need to add a firewall rule that allows TCP port 22 inbound.
sudo ufw allow 22/tcp
Next: Enable SSH Root Login
Connecting to the Ubuntu via ssh command
The ssh command is a command line SSH client available in every Linux/Unix operating system. It is a very simple and easy to use SSH Client for Ubuntu Linux.
To connect to that server via SSH, execute the ssh command followed by the IP address or domain name of the Ubuntu server:
The ssh command by default will try to log in to the remote server with the same username you are using on your local Linux machine. For example, if you have logged in to your local Linux machine as a root user, then the ssh command will try to connect to the remote server as the root user.
If you want to login as a different user, use the -l option:
ssh -l user 192.168.1.100
Alternatively, you can also use the following format ([email protected]):
On windows you can get SSH command by installing the GIT bash shell or you can use an SSH client like Putty.
Also by default ssh command will connect to the remote server via port 22, which is the default SSH port. If you have changed the port for SSH on your Ubuntu server, then use the -p option to specify the port to connect to on the remote host:
ssh -p 22000 192.168.1.100
In the preceding example, we connect to the remote server via port 22000.