You may often have to access remote servers to administer, manage, and troubleshoot and there are several ways to do this. You may use telnet to login to remote servers; FTP allows transferring files between different servers. However, these programs are not secure enough for connecting to critical servers. SSH, secure shell is a cryptographic network protocol using which you can securely access network services over an unsecured network. SSH allows you to access servers through Terminal and various command line functions. It is helpful if you want to access and administer a server remotely using a secure way.
In this article, I am going to describe how you can remotely manage a Linux server with SSH.
For this article, I am using the following machines:
- For SSH Server – Ubuntu 18.04 TLS
- For SSH Client – Terminal (Ubuntu) & Putty (Windows)
Establishing the SSH connection
Prior to establishing a secure remote connection with a Ubuntu server using SSH, you have to meet some basic requirements.
Following are some prerequisites:
- The remote server must be powered on and have a stable network connection.
- You will require an IP address of the server.
- The remote server must be accessible through that IP. You can test it using a Ping command.
- SSH server and SSH client tools must be installed in both server and client OS respectively.
- You will require a remote server’s user name and password.
- A Firewall should not be blocking the connection.
Installation of OpenSSH server
To manage a Ubuntu server remotely via SSH, you will need the SSH server software. However, before proceeding for installation of OpenSSH, first, update and upgrade the list of packages to get the most up-to-date repositories.
Update package database
Press Ctrl + Alt + T to launch Terminal in Ubuntu. Enter the following command in Terminal to update package database.
$ sudo apt-get update
Upgrade installed packages
After updating repositories, run this command in Terminal to check for an upgrade for installed packages.
$ sudo apt-get upgrade
Once you have updated and upgraded the packages, run the following command in Terminal:
$ sudo apt-get install openssh-server
Configuring SSH Server
Now you will need to do some basic and necessary configuration of SSH server in ssh_config file. For this, run the following command in Terminal to open ssh_config:
$ sudo nano /etc/ssh/ssh_config
You can do various configuration settings here. For now, we will do only basic and starting configuration as shown in the below screenshot. Uncomment the below line in ssh_config file:
Under port number, add the line MaxAuthTries. You can enter here any number that will allow a maximum number of login attempts.
Once done with the basic configuration, save the file and exit the Nano editor.
Check SSH service status
To check the status of the SSH server, if it is running or not, you can run the following command in Terminal:
$ sudo service ssh status
Above command confirms that SSH service is active and running.
Now SSH server is set up to accept remote connections from different computers using a SSH client.
If the SSH service is not running you can run it manually by running the following command in Terminal:
$ sudo service ssh start
You can also stop SSH service by running the following command in Terminal:
$ sudo service ssh stop
Accessing Ubuntu Linux server through SSH client
You can access a Linux server through SSH client in Linux or Windows based OS:
- Through Terminal ( Linux )
- Through Putty (Windows )
If you are using a Linux operating system, you can access SSH server using the Terminal program.
Press Ctrl+Alt+T to launch Terminal. Run the command in the below syntax to access a remote server:
$ ssh [remote server] [Port Number]
Where [remote server] is the remote server name or IP and [Port Number] is the remote port for SSH connections.
Or you can also type the command along with the username of the remote server in the following syntax:
$ ssh [username]@[remote server] [Port Number]
Where [username] is the name of the remote server user.
Type yes when it prompts the message asking if you want to continue connectivity. It will add the user to the list of known hosts. Next time you connect, it will not prompt the message again.
When prompted for the password, type the remote user’s password.
Now you are connected to the remote server. You can run any command and use it the same way as you access a local server.
Connect to Ubuntu from Windows using Putty SSH client
If you are using a Windows operating system, you can use putty as an SSH client.
Install putty in your Window OS. To launch Putty, Type putty in the search bar of Windows, and select putty.exe from the best match results.
In the putty configuration window, under session category, type IP address of the remote server in the box labeled as Hostname (or IP address).
From connection type, select SSH radio button. If you are using a port other than default port 22, make sure to change it otherwise leave the default port 22. Then click on Open to allow the connection.
A Terminal will open with a login prompt. Enter the username and password of the remote server user.
After you have successfully logged in to the remote server, you can run any command to manage it.
This is how you can easily connect the Linux servers using SSH. Now you are able to manage and administer the server remotely. SSH is not only a secure method of connecting to a server but also convenient.