- How to install and use SSH on Linux
- Configure SSH on a Local Computer
- Configure SSH on a Remote Computer
- Install SSH server
- Check SSH status
- Find out Server’s IP
- Open SSH port in Firewall
- Connect using SSH
- SSH in FileZilla
- SSH in File Manager
- Forward X
- Transfer files
- Final thoughts
- How to Check if SSH is Running on Linux
- SSH running on Linux
- SSH process
- SSH port
- SSH service
- Stopping SSH
- Starting SSH
- Enabling/disabling SSH
- Final thoughts
- About the author
- Sidratul Muntaha
- How to check if SSH is running on Linux?
How to install and use SSH on Linux
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
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 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 openssh-server .
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 openssh-server program.
Check SSH status
After the installation, check that SSH is running with:
sudo systemctl status ssh
You should see that it is active:
If it has not started, start it manually:
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:
If you only have the command line, run:
Usually, you will see your IP address in the eth0 connection.
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:
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:
ssh remoteuser@remote-ip-address
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.
Forward X
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.
Transfer files
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.
Final thoughts
As you have seen SSH is a pretty handy program. It is not difficult to install and use. There are some more configurations you do to your SSH. I recommend enhancing the security of your SSH connection with SSH keys and white-listed IP addresses.
Average Linux UserFollow I am the founder of the Average Linux User project, which is a hobby I work on at night. During the day I am a scientist who uses computers to analyze genetic data.
How to Check if SSH is Running on Linux
SSH is a cryptographic network protocol that lets you control and modifies a remote computer over the internet. This protocol ensures security even through a vulnerable network. Most of the Linux distros use OpenSSH, an open-source project implementing the SSH protocol.
In this guide, we’ll demonstrate how to verify if SSH is running on Linux.
SSH running on Linux
There are multiple methods to detect if SSH is currently running on the system.
Note that SSH is divided into two sections in terms of functionality: the SSH client and the SSH server. The client connects to the server using the SSH protocol. An SSH key is the default security measure to protect the connection.
If SSH is installed and enabled, then it’s likely that the SSH server is up and running on the system, waiting for an SSH connection request. We can detect if the SSH server is running, but it doesn’t give info if an SSH connection is active. We can verify that if the SSH port is currently open.
SSH process
This is the first step in verifying whether SSH is currently running. We’re looking for the status of the sshd process. This guide details working with Linux processes.
Use the ps command to list all the processes and filter the output using grep to check if the SSH process is running.
Depending on the state of the process, the output will differ.
SSH port
Every process/service in Linux gets its dedicated port to communicate over the network. SSH, by default, is configured to use port 22 for remote communication. Note that it’s possible to configure a different port for SSH. It’s a good security measure to prevent various attacks, for example, DDoS or brute-force.
Even if a program is dedicated to a specific port, the port won’t be open if the program isn’t running. We can use this trick to verify whether SSH is running. If the port is open, then SSH is up and running.
To check the list of open ports, we’ll be using the netstat tool. It’s a dedicated tool for printing various network info like network connections, routing tables, interface stats, etc. This guide demonstrates the in-depth usage of netstat.
The following command will check if SSH is listening to port 22. If SSH is configured to listen to a different port, use that port instead.
An alternative method to check open ports is checking the port file. The following command will print the list of all the open port files.
Another method is to telnet to the SSH port.
Depending on whether port 22 is open, the output will vary.
SSH service
The SSH service manages the state of the feature. The following command will print the SSH service status.
Stopping SSH
By default, SSH is configured to start at boot. If having SSH up isn’t necessary at the moment, then we can stop it. Note that it requires the root account or non-root user with sudo privilege to change service.
The following command will stop the SSH service.
Starting SSH
If SSH isn’t up and running, then start the SSH service. It should load all the components and ready to accept SSH connections.
Enabling/disabling SSH
If a service is enabled, it means that the system will start the service at boot. The system won’t start a disabled service at boot.
The following command will disable the SSH service. Note that to use SSH afterward, the service has to be started manually.
The following command will mark the SSH service “enabled”.
Final thoughts
SSH is a powerful feature that makes remote management a lot simpler. Its inherent secure nature and simplicity make it the industry standard for remote system management. SSH is part and parcel of a system admin’s everyday life.
Working with multiple remote systems? Then consider using Ansible to manage all of them. Ansible is a configuration management system that uses SSH to connect and manage multiple remote systems. It’s a robust framework to manage all your remote systems from one place.
About the author
Sidratul Muntaha
Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.
How to check if SSH is running on Linux?
Question – I need to check whether SSH (sshd) is running on my Linux machine. I have a Debian Linux distribution. How can I tell if my OpenSSH server is running?
There are several ways to check whether SSH is running. The sshd daemon is the process that runs the OpenSSH ssh server.
First Check if the process sshd is running:
This will output something like the following if it finds the process called sshd:
[root@server ~]# ps aux | grep sshd root 1399 0.0 0.2 8292 1092 ? Ss Sep13 0:00 /usr/sbin/sshd [root@server ~]#
So sshd is running with process ID 1399! It is indeed running!
Second, check if the process sshd is listening on port 22:
If ssh is listening on port 22, you will get the following:
[root@server ~]# [root@server ~]# netstat -plant | grep :22 tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1399/sshd tcp 0 0 . 22 . * LISTEN 1399/sshd [root@server ~]#
So the process with ID 1399 (sshd) is listening on port 22! The second test passed!
Third, you can use the lsof command to check if the port 22 TCP file is open:
[root@server ~]# lsof -i COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME sshd 1399 root 3u IPv4 1235481137 0t0 TCP *:ssh (LISTEN) httpd 6126 root 3u IPv4 1309891499 0t0 TCP *:http (LISTEN) [root@server ~]#
So sshd (SSH daemon) and httpd (Apache web server daemon) are both running and listening on the ssh and http ports respectively! Third test passed.
Four, try to telnet to port 22:
If the port is open, you will get the following output:
[root@server ~]# telnet localhost 22 Trying ::1. Connected to localhost. Escape character is '^]'. SSH-2.0-OpenSSH_5.3
If the port number 22 is not open, you will get the following:
[root@server ~]# telnet localhost 22 Trying ::1. telnet: connect to address ::1: Connection refused Trying 127.0.0.1. telnet: connect to address 127.0.0.1: Connection refused [root@server ~]#
Five, check the status of the sshd service:
If you use CentOS or Red Hat:
[root@server ~]# service sshd status openssh-daemon (pid 1399) is running. [root@server ~]#
If you use Debian or Ubuntu (or CentOS or RedHat):
[root@server ~]# /etc/init.d/sshd status openssh-daemon (pid 1399) is running. [root@server ~]#
So these were five interesting methods in which you could check if the SSH OpenSSH server is running and listening on port 22. If the process sshd is misbehaving or not listening on port 22, one of these methods will surely fail and you should start or restart sshd using the following command:
[root@server ~]# /etc/init.d/sshd restart Stopping sshd: [ OK ] Starting sshd: [ OK ]