SSH (Secure Shell) is a cryptographic network protocol used for securing the remote login between server and client. SSH is a replacement for Telnet and other shell protocols such as rlogin, rsh, and rexec protocols.
Enabling SSH on Ubuntu is one of the tasks to do after the fresh installation of OS and helps you to connect your system remotely and perform tasks securely.
To be able to enable SSH service, you need to be logged in as a root user or a user with sudo privileges.
Enable SSH on Ubuntu / Linux Mint / Debian
The reason you are not able to use SSH is that SSH server package is not installed on Ubuntu or Linux Mint or Debian by default. The SSH server package is available in the OS base repository, and it can be easily installed with apt command.
Open up a terminal with Ctrl + Alt + T.
Install SSH Server package using apt command.
sudo apt update sudo apt install -y openssh-server
The SSH service will start automatically upon the completion of package installation. You can verify the SSH server package installation 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
You may need to allow SSH incoming connections in firewall (Thanks to @arocee). So, use the below command to create a rule in UFW to allow SSH connections from external machines.
sudo ufw allow ssh sudo ufw enable sudo ufw reload
Access Ubuntu / Linux Mint / Debian Machine via SSH
You can connect to your system via SSH using putty from Windows or built-in SSH clients from Linux or macOS.
Enter the machine’s ip in the session window and click Open.
When you connect to the Ubuntu system for the first time, You may get a pop-up window to accept fingerprint. Click Yes to connect.
Enter the user’s password to login to the system. Upon successful login, you will get the shell prompt.
ssh [email protected]_address
When you connect to the Ubuntu system for the first time, you will get a below message. Type Yes to continue connecting to your system.
The authenticity of host '192.168.1.10 (192.168.1.10)' can't be established. ECDSA key fingerprint is SHA256:sueTz6FURcKDbeyGkpE7lUHOaosW/rkkvlG18v98T7Y. Are you sure you want to continue connecting (yes/no)? Yes
Enter your system password.
Warning: Permanently added '192.168.1.10' (ECDSA) to the list of known hosts. [email protected]'s password: << Enter Password
On successful login, you will see a message similar to this.
Welcome to Ubuntu 18.04 LTS (GNU/Linux 4.15.0-20-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage 587 packages can be updated. 261 updates are security updates. Last login: Tue Apr 30 09:03:34 2019 from 192.168.1.6 [email protected]:~$
You are now in into your system, and you can start performing administration tasks.
Enable SSH Root Access on Ubuntu / Linux Mint / Debian
By default, root login over SSH is not allowed on Ubuntu / Linux Mint / Debian. But, you can enable root login by editing the SSH configuration file.
Edit the sshd_config file.
sudo nano /etc/ssh/sshd_config
Set the PermitRootLogin to Yes
Restart the SSH service.
sudo systemctl restart ssh
Now you should be able to login directly as the root via ssh.
Disable SSH on Ubuntu / Linux Mint / Debian
For any reason you want to disable SSH on your system, you can just stop the SSH service by running below command.
sudo systemctl stop ssh
Also, you need to disable the SSH service so that it doesn’t start on system reboot.
sudo systemctl disable ssh
Additionally, you can set up SSH Key-based authentication to connect to your Linux system without entering a password.
You can visit the official SSH manual page for more information on configuring SSH service.