You can see the “connection refused” message in the output. It means that the SSH server is not installed on your system.
Before installation, update system repositories.
sudo apt update
Now you can install the OpenSSH package by running the following apt command.
sudo apt install openssh-server
Once installation is completed, enable the SSH using the following command.
sudo systemctl enable --now ssh
Once SSH is enabled, run the following command to confirm the ssh server status.
sudo systemctl status ssh
You can see the output says “active (running)” in the active field. It means that your server is running.
Ubuntu comes with firewall called uncomplicated firewall (UFW). You have to change settings so that it allows your SSH server connections using the following command.
sudo ufw allow ssh
Once the server-side is configured, you are now ready to connect your local system with the remote system.
To connect your local system with the server, You need to have an SSH client on your local system.
You can install the SSH client with the following command.
sudo apt install openssh-client
We need the IP address of your local system to connect to the SSH server. Run the following command and note your system IP address.
ip a
To connect to SSH, run the following command with your username and public ip address.
ssh username@address
Provide a password to log into the SSH server.
SSH server has a couple of default settings you should change for a more secure connection.
First, open the SSH configuration file.
sudo nano /etc/ssh/sshd_config
The port is set to 22 by default, change it to another port.
Additionally, set the PermitRootLogin field to “no”.
You can make other changes for further customization.
If you wish to start or stop SSH service in your system, you can use the following command to do so.
sudo systemctl start ssh
sudo systemctl stop ssh
You can enable the SSH service using the following command. It will automatically start the SSH service at the system boot.
sudo systemctl enable ssh
Disable the SSH service with the following command. It will not stop the current SSH session but stop the service from automatically starting at the system boot.
sudo systemctl disable ssh
This article discusses the installation, setup, and configuration of SSH in a Ubuntu system. You can now connect to a remote device using a safe and reliable SSH. With SSH as a server you can securely log in and work remotely.
Most Linux operating systems provide the SSH tool, but this is not the only option. PuTTY is a famous SSH client for Windows. But you can also install and use PuTTY on Ubuntu. PuTTY is an alternative for connecting to your Ubuntu system from a Windows computer.