How to install and use SSH on Linux
SSH or Secure Shell allows you to connect between computers and encrypt traffic between them.
For example, I use SSH to connect to my virtual private server and to my office computer. Usually, it works only through the terminal. However, you can connect it to your file manager or use some graphical programs like FileZilla, if you do not want to type commands. You can also use graphical forwarding and open graphical programs from the remote server in your local computer.
SSH is a simple, reliable, and very secure way to establish a connection between computers. In this post, you will learn how to install, configure, and use SSH on Linux. In particular, I will show how to:
- Configure SSH on a Local Computer
- Configure SSH on a Remote Computer
- Connect using SSH
- SSH in FileZilla
- SSH in File Manager
- Forward X
- Transfer files
Configure SSH on a Local Computer
First, you need to set up your client Linux machine. This is the computer you will use to connect from.
You need to install
openssh-client on your Linux computer.
sudo apt install openssh-client
sudo pacman -S openssh
sudo zypper install openssh
sudo dnf install -y openssh-clients
If you also need to use Windows as a client install PuTTY.
Configure SSH on a Remote Computer
Next, configure the computer you want to connect to.
Install SSH server
On the remote computer, you need to install
sudo apt install openssh-server
sudo pacman -S openssh sudo systemctl enable sshd sudo systemctl start sshd
sudo dnf install -y openssh-server sudo systemctl enable sshd sudo systemctl start sshd
sudo zypper install openssh sudo systemctl enable sshd sudo systemctl start sshd
Obviously, you will need to have physical access to the remote computer to install this package. For example, if it is my office computer, I will go to my office and install this
Check SSH status
After the installation, check that SSH is running with:
sudo systemctl status sshd
You should see that it is active:
If it has not started, start it manually:
sudo systemctl start ssh
or simply reboot the system.
Find out Server’s IP
Next, you need to determine the IP address of this remote computer.
The easiest way is to check the network settings. If you have a graphical desktop in that computer, open the network settings and search for IP address.
This is how it looks in Plasma 5:
And in Ubuntu GNOME:
If you only have the command line, run:
Usually, you will see your IP address in the
Write down this address, you will need it to be able to connect to this remote computer.
Open SSH port in Firewall
It is possible that you use a firewall and it may block your remote access. So, check open ports:
sudo lsof -i -P -n | grep LISTEN
You should see that port 22 is open. If you do not find port 22 open among open ports, go to your firewall settings and open it.
If you use UFW run this command:
sudo ufw allow 22
I discuss whether you need a firewall in Linux and how to use it in this post.
Connect using SSH
Now, I assume your remote computer is configured and you are sitting in front of your client Linux machine.
In your client Linux computer, run:
You use the username of the remote computer and the IP address is the address you wrote down in a previous step.
If you get a warning “Are you sure you want to continue connecting (yes/no)?”, type yes.
After you typed the password of your user at the remote computer, you will be logged in to a remote Linux computer.
Now, you can work on this remote computer as if you would be sitting in front of that computer and using the terminal.
SSH in FileZilla
If you simply want to work with files without running any programs, you can also connect to your remote server with FileZilla.
In FileZilla, go to the Site manager and add a new site with SFTP protocol:
You will get your local files on the left and your remote files on the right.
You can navigate in FileZilla with your mouse and transfer files between your computers by simple drag-and-drop between these two panels.
SSH in File Manager
Similarly, you can add the remote server to your File Manager. I use Dolphin file manager of Plasma 5 but the procedure is very similar in other file managers.
Go to the Network in your file manager and add a Network folder:
Among these options, select SFTP protocol, give a name to this folder, provide the user name of the remote account, IP address of the remote computer. In the field “remote folder path”, you can use your remote user home folder or any other folder you want to connect to.
As a result, you will see all the folders and files of your remote computer in your file manager.
You can also forward graphical application from your remote computer to your local computer. To do that, you simply need to add the option
-X during the login.
ssh -X remoteuser@remote-ip-address
Now, if you start any graphical program in a remote computer, it will open in your local computer, like this Firefox on the screenshot.
To transfer a file to a remote computer in the terminal run:
scp /path/to/local/file remoteuser@remote-ip-address:/path/to/remote/file
And to transfer a file from a remote computer to your local computer simply type first the remote address and then local.
scp remoteuser@remote-ip-address:/path/to/remote/file /path/to/local/file
You can also use wild cards to transfer many files at the same time. I showed how to use wild cards in this YouTube video.
As you have seen SSH is a pretty handy program. It is not difficult to install and use. However, there are some more configurations which I did not cover in this post. For example, you can enhance the security of your ssh connection with SSH keys and white-listed IP addresses. I will cover this topic in the next post. So, subscribe to this blog updates and you won’t miss it.
Thank you for reading.