What is SSH and how to use it? Here are the Secure Shell basics you need to know


If you need to do remote machine administration, at some point you’ll need to connect to a Linux server and get to work. To do this, you will need to use SSH (or Secure Shell). For those who have never encountered such a tool, you will be delighted because it not only allows you to easily connect to remote systems, but it is also very secure.

What is SSH?

SSH is a secure way to connect to a remote machine. Once connected, you can run all the commands you need to work with the server. And no, using SSH is not difficult. Using SSH is not only relatively easy, but it is also very powerful.

How to use SSH to connect to a remote server


What you will need: I’ll walk you through the first steps of using SSH. I’m going to demonstrate on Linux Pop!_OS but this information will work on any Linux distribution that supports SSH (which most of them do).

The only things you’ll need to follow this tutorial are two running instances of Linux. There it’s done ? So let’s take action with SSH.

1. Connect to a remote machine

Using SSH allows you to connect to a remote machine from a local machine. You will need user accounts on both machines. These accounts don’t have to be the same on each machine (I’ll explain that in a minute), but you do need to have login credentials for both.

You will also need the IP address (or domain) of the server you want to connect to. Let’s say, for example, that our remote server has the IP address 192.168.1.11 and our user account is the same on both machines. Log in to your desktop computer, open a terminal window, and connect to the remote machine using the command:

ssh 192.168.1.11

You will be asked for your username on the remote machine. Once you authenticate with the password, you will be connected to the remote machine, where you can start working.

2. Log in via domain name

Suppose the remote machine is associated with the domain www.example.com. You can connect to it using the following command

ssh www.example.com

3. Log in using a different username

Now, what if your username on the remote machine is not the same as the one on the desktop? If your username on the remote machine is olivia, you can log in using the command:

ssh [email protected]

You will be asked for Olivia’s password (not the local user’s).

4. Connect via a non-standard port

Normally, SSH uses port 22. Some administrators may change this port (for security purposes). If the server administrator has configured SSH to listen on port 2022, you cannot simply type the standard SSH command to connect. Instead, you must add the -p option (for port) as follows:

ssh [email protected] -p 2022

Configuring the SSH site

Remembering all those IP addresses and usernames can be a real headache for some. Fortunately, SSH allows you to create a configuration file that contains all of this information. For example, suppose you have the following list of servers that you connect to:

  • web server – 192.168.1.11
  • email server – 192.168.1.12
  • database server – 192.168.1.13

Let’s configure SSH so that you only need to connect using the commands:

  • ssh web1
  • ssh email1
  • ssh db1

1. Create a configuration file

We’ll also assume that the user on web1 is olivia, the user on email1 is nathan, and the user on db1 is the same as the user on the local machine. To set this up, we need to create a configuration file in the ~/.ssh directory. To do this, return to the terminal window on your local machine and run the command:

nano /home/USER/.ssh/config

Where USER is your Linux username.

2. Configure the file

In this file, add the following lines:

Host web1
Nom d'hôte 192.168.1.11
Utilisateur olivia

Host email1
Nom d'hôte 192.168.1.12
Utilisateur nathan

Host db1
Nom d'hôte 192.168.1.13

Save and close the file. You should now be able to connect to these different servers using the shortest commands (i.e. ssh web1, ssh email1 and ssh db1). It is important to remember, however, that for web1 you will be asked for Olivia’s password, for email1 you will be asked for Nathan’s password, and for db1 you will be asked for the same user as user local.

Run commands on a remote machine with SSH

It’s a handy little thing. Let’s say you don’t necessarily want to connect to a remote machine but need to run a command. For example, you want to list the contents of the remote user’s home directory. To do this, you can run the following command:

ssh [email protected] ls /home/olivia

Since we have our configuration file in place, we can truncate this command to:

ssh web1 ls /home/olivia

We can cut a little more out of this command because Linux has a shortcut for a user’s home directory (because /home/olivia and ~/ are the same thing). For this, our command becomes:

ssh web1 ls ~/

And there you have it, my dear friends, the basics of using SSH to connect to a remote Linux machine. If you ever need to administer a Linux machine remotely, this is what you need to know. Next time, I’ll introduce you to SSH key authentication, for even more secure remote connections.


Source: “ZDNet.com”



Source link -97