How To SSH Into A Remote Server


ssh

Introduction

SSH, short for Secure Shell, is a protocol used to securely log into remote systems. It’s the most common way to access remote Linux servers.

When a secure SSH connection is established, a shell session will be started on the remote server, and you will be able to manipulate it by typing commands in the SSH client on your local pc.

ssh into remote server
Example of a SSH terminal.

As a Systems Admin, SSH is a essential tool to perform your daily tasks. Otherwise you would need to be in front of the keyboard or through a virtual remote session like IPMI.

Requisites

You need a SSH client, the hostname or IP of the remote server, the username and password to login. OpenSSH is one of many clients available and the most widely used today. However, there are different clients available that provide different features to the user, you can learn more about them in the following post “The Best of SSH Clients“.

Connect via SSH

Open the terminal on your machine and run the following command:

  localhost:~$ ssh username@hostname.com

And hit Enter.

Type in your password and hit Enter.

Note: that you will not get any feedback on the screen while typing it.

The authenticity of host 'hostname.com' cannot be established.
DSA key fingerprint is 04:48:30:31:b0:f3:5a:9b:01:9d:b3:a7:38:e2:b1:0c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ' 185.52.53.222' (ECDSA) to the list of known hosts. 

When you are connecting to a server for the very first time, it will ask you if you want to continue. Type yes and hit Enter. This message appears only this time since the remote server is not yet identified on your local machine.

Common SSH Options

localhost:~$ ssh -v -p 22 username@hostname.com

-v : Print debug information, particularly helpful when debugging an authentication problem. It can be used multiple times to print additional information.

-p 22 : Specify which port to connect to on the remote SSH server. 22 is not required as this is the default, but if the server is listening in a different port you connect to it using the -p parameter.

Note: The listening port is configured in the sshd_config file.

Executing remote commands on the server

As you may know, the SSH client is often also used to remotely execute commands on the remote machine without logging in to a shell prompt. The syntax for this is shown in the following example:

 localhost:~$ ssh username@hostname.com "uptime"

In the above example, after authenticating to the remote server, it will output the remote server uptime. This option is very useful for Bash Scripting and sending commands to multiple servers with only a few lines of code.

Conclusion

SSH is a secure way to access a remote server, it made unencrypted “Telnet” sessions obsolete. You can use it to safely transfer files over a network using SCP, or to send automated commands using Bash Scripts. It’s pretty awesome, right?

If you to want learn more about this tutorial or have any questions, feel free to send your comments down below.

Don’t forget to check our other Tutorials, we are constantly submitting new ones every week.

Tags: , , ,

Buy us a Coffee

Categories

Recent Posts

RSS Other Tutorials