All the things you need to know about SSH (Secure Shell)

You could at some point require remote access to a Linux machine. When that happens, SSH will be necessary. So we are introducing you to the beginner guide on SSH.

If you ever need to perform any remote administration, you will eventually need to log in to a Linux server and start working. You must utilise SSH to accomplish it. Those of you who have never used such a tool is in for a gift.

What is SSH?

SSH is a safe way to access a remote computer. You can issue whatever command you need to work with the server once you've logged in. Don't worry if you're worried that utilising SSH will be challenging. SSH is not only quite simple to use, but it is also very powerful.

So let's get started with SSH

Login Basics SSH

You can log in from a local computer to a distant computer by using SSH. On both computers, you'll need user accounts. These accounts don't need to be identical on every computer.

Additionally, you will want the IP address (or domain) of the server you wish to access. Consider, for illustration's sake, that our remote server has the IP address 192.168.1.12 and that both computers share the same user account. Open a terminal window on your desktop computer, and log in to the distant system using the following command:


ssh 192.168.1.12

        

The remote computer will ask you for your username. You can begin working on the remote system once you have successfully authenticated using the password.

What happens if your username on the distant machine differs from your desktop username? Let's say that Arun is your username on the remote computer. The command to log in with that username is:


ssh Arun@192.168.1.12
        

When prompted, enter Arun's password rather than the local user's. Port 22 is typically used by SSH. Some system administrators may alter that port (for security purposes). The default SSH command won't work if the server administrator has set SSH to listen on port 2022. The -p option must be added in the following manner instead:


ssh Arun@192.168.1.12 -p 2022
        

SSH Site configuration

For some people, keeping track of all those usernames and IP addresses might be a tremendous hassle. Thankfully, SSH enables you to build a configuration file that contains all of this data. Consider the following list of servers you regularly log into:

  • webserver - 192.168.1.11
  • email server - 192.168.1.12
  • database server - 192.168.1.13

Let's set up SSH such that you only need to enter the following instructions to log in:

  • ssh web1
  • ssh email1
  • ssh db1

Additionally, we'll definitionally assume that Elizabeth, Adam, and the same user as on the local machine are the users of web1, email1, and db1 respectively. We need to build a configuration file in the /.ssh directory to configure this. Return to your local machine's terminal window and enter the command to do it.

In that file, add the following lines:



Host web1
   Hostname 192.168.1.11
   User Arun

Host email1
   Hostname 192.168.1.12
   User Elizabeth

Host db1
   Hostname 192.168.1.13

        

Save the document, then exit. With the shorter commands, you should now be able to log onto those various servers (i.e. ssh web1, ssh email1, and ssh db1). But it's vital to keep in mind that for web1, email1, and db1, you'll need to provide Arun's password, Elizabeth's password, and the same user as the local one.

Running commands on a remote machine with SSH

This simple tip is very helpful. Consider the scenario when you need to execute a command but don't necessarily want to log into a remote computer. You could want to list the contents of the remote user's home directory, for instance. You could do that by giving the order:


ssh Arun@192.168.1.12 ls /home/arun
        

After configuring the file type, we can shorten that command to:


ssh web1 ls /home/arun
        

Because Linux offers a shortcut for a user's home directory, we can shave off a little more from that command.


ssh web1 ls ~/
        

And that is the fundamentals of logging into a distant Linux machine using SSH. You will need to know this if you ever need to remotely administer a Linux machine. For even more secure remote logins, we will introduce you to SSH Key Authentication at the following time.

To view or add a comment, sign in

Explore topics