How to connect server as root via SSH

What is SSH?

The Secure Shell (SSH) protocol, also known as Secure Shell or Secure Socket Shell, is a network protocol that allows administrators to access computers over unsecured networks in a secure manner. SSH is also a suite of utilities for implementing the SSH protocol in addition to providing secure network access. The SSH suite consists of three tools, slogin, SSH, and scp, which are secure versions of the earlier UNIX utilities known as rlogin, rsh, and rcp. Many ways of encrypting and securing SSH commands exist.

With Secure Shell, you can use public keys and strong passwords to authenticate, as well as encrypt your data transfer between two computers connected to an open network like the internet. Network administrators use SSH to manage systems and applications remotely, logging in to another computer over a network, executing commands, and transferring files between computers.

To put it simply, SSH allows you to safely access your server and perform Linux command-line operations. Despite the fact that you will be running Linux commands, you can still perform SSH on a computer running Windows, Mac, or Linux.

Introduction

We barely imagine how life would be without remote access to computers. Taking control of computers from a distance has existed for a very long time now. Based on the operating system you use, there are multiple methods of connecting to a remote machine. SSH is one of the most used protocol. Clients and servers are used to establish remote connections over protocols. Accessing and managing other computers remotely, transferring files, and doing virtually anything you can do when physically sitting in front of the computer are all possible with these tools.

It’s not to hard to connect server as root via SSH. All you have to do is detailed in this article as follows.

Pre-requisite for SSH

It is imperative that you meet the following requirements before you are able to establish a secure remote desktop protocol:

  1. You must have a network connection and keep the remote computer on at all times.
  2. Installation and activation of client and server applications are required beforehand.
  3. If you wish to connect to a remote machine you need to know its IP address or name.
  4. Accessing a remote computer requires that you have the proper permissions.
  5. Remote connections need to be allowed in the firewall settings.

Now that you fulfilled all the requirements before hand let’s move ahead and connect server.

An SSH connection can be established by using two components: the client and the server-side component. SSH clients allow you to connect to another computer or server using an application installed on your computer. Once credentials are verified, the client establishes an encrypted connection using the provided remote host information.

SSH: How does it work?

Servers run a program called an SSH daemon, which is always listening for possible client connection requests on a specific port. As soon as a client initiates a connection, the SSH daemon responds with information about the client system and about the protocols currently supported by it, and the two exchange identification information. A new SSH session is created for the environment if the credentials are correct. Communication between an SSH client and server uses version 2 of the SSH protocol by default.

How to Install an OpenSSH Client

A local and remote machine must each have an SSH client and server installed before you can create an SSH connection. The OpenSSH tool is widely used for Linux distributions as an SSH tool. Getting OpenSSH up and running is fairly straightforward. Only the machine you use for connecting and the server terminal are required. Ubuntu by default does not include an SSH server. In that case you need to install SSH server.

Make sure you do not already have an SSH client installed before beginning the installation. An SSH client is included in most Linux distributions. Access a server through PuTTY or any other client you choose if you are using a Windows machine.

For Linux users, it is important to check whether the client is available by doing the following:

  1. Run SSH from an SSH terminal. You can open terminal by pressing CTRL+ALT+T on your keyboard or simply by searching “terminal”.
  2. In the terminal, type SSH and press Enter.
  3. When the client is installed, you will receive a response similar to this:

If you see this message, you are ready to remotely interact with a physical or virtual machine. If not, you’ll need to install OpenSSH:

  1. Install the OpenSSH client by running the following command:

sudo apt-get install openSSH-client

  • You will be prompted for your superuser password. Enter the password then.
  • The installation will be complete when you press Enter.

As long as you have the proper permissions and know the hostname or IP address of any machine with the server-side application on it, you can SSH into it.

Now that you have successfully installed openSSH client let’s quickly install openSSH Server.

Install an OpenSSH Server:

An SSH connection can only be accepted by a machine if it has the server-side interface of the SSH software toolkit installed. You can connect to the local host first to check if OpenSSH server is available on Ubuntu system of remote computer.

  1. Run SSH from an SSH terminal. You can open terminal by pressing CTRL+ALT+T on your keyboard or simply by searching “terminal”.
  2. In the terminal, type SSH localhost and press Enter.
  3. A system without an SSH server will respond as follows:

OpenSSH server will need to be installed if it is the case mentioned above. The terminal should be left open, and you should:

  1. Installing the SSH server is easy with following command: sudo apt-get install openSSH-server ii.
  2. When prompted, type in your superuser password.
  3. When the disk space prompt appears, enter and hit Y to allow the installation to continue.

As soon as the SSH server is installed, you may test that it is running by typing the following command:

sudo service SSH status

You should see something similar to this in the terminal if you have correctly installed SSH server:

How to connect server via SSH

You can now establish a secure remote connection to your servers after installing the OpenSSH client and server on every machine you need. Here’s how to do it:

  1. On your machine, open your SSH terminal and run this command:

SSH your_username@host_ip_address

In this case, you just need to type: SSH host_ip_address and hit enter if your local machine’s username matches your server’s.

  • Hit Enter after entering your password. It’s important to keep in mind that during typing, no feedback will appear on the screen.  When pasting your password, ensure it’s safe and not in a text file.
  • You will be asked for your consent when you’re connecting to a server for the very first time.  You can type yes and press Enter key.  It appears only this time because the remote server has not been detected on your local machine.
  • Your ECDSA key fingerprint has now been added and your connection to the remote server has been established. Bravo!

Using a private IP address instead of the public IP address is recommended when you are trying to remotely connect to a computer on the same network.  If not, you will be restricted to using public IP addresses only. Also, make sure you know what TCP port OpenSSH listens to when it receives connection requests and that the port forwarding configuration is correct. As long as the SSHd_config file is not changed, port 22 is the default.  After the host IP address, you can also add the port number.

The conclusion

A remote machine can now be managed and controlled by your terminal. In case of problems connecting to a remote server, make sure:

  • You have entered the correct IP address of the remote machine.
  • There is no firewall blocking or incorrect routing for the port where the SSH daemon is listening.
  • You have entered the correct username and password.
  • Installing SSH has been successful.

Other methods of connecting remotely can also be taken, but the ones that were covered in this post are among the most common.

Leave a Comment

Your email address will not be published. Required fields are marked *