How to Set Up and Use SSH in Linux

How to Set Up and Use SSH in Linux

 222 total views


2021-08-19 07:52:10

If you’re using Linux, you’ve probably heard of a tool called SSH. Secure Shell, commonly known as SSH, is a network protocol for establishing secure connections between remote clients and servers. It is designed to allow users to securely log on to a variety of computers remotely over the network. Here, the article will show you how to set up and copy SSH keys to the server easily.

SSH Settings

To get started, you must install an SSH server. You can find and install the package openssh-server in Software Center or package manager. Alternatively, if you’re on a server (or just prefer to use Terminal), open a Terminal and enter the following command:

Ubuntu/Debian

sudo apt install openssh-server

Fedora/CentOS/REHL

sudo dnf install openssh-server

Enable SSH in Linux

After the OpenSSH server has been installed on your machine, you need to start it and activate it systemd. To do that, simply type the following command into Terminal:

sudo systemctl enable --now ssh

Generate SSH key

Once the openssh server is installed, you can start generating SSH key pairs. Before continuing, make sure you don’t have any existing key pairs, as this process will overwrite an existing key pair.

To check if you currently have a key pair, use the command:

ls -la ~/.ssh

If you currently have a key pair, the above command will display the files “id_rsa” and “id_rsa.pub”.

The files “id_rsa” and “id_rsa.pub” are displayed

After verifying that you currently do not have an SSH key pair, you can proceed to generate a new one. If not, back up the old keys to avoid losing them.

To generate a new key, use the command:

ssh-keygen -t rsa -b 4096

The above command calls the utility ssh-keygen to generate SSH key pairs interactively. Use option -t to specify the type of key to be generated. In this case, the example will generate an RSA key.

The example also uses the -b option to specify the number of bits in the key. If you use an RSA key, the minimum bit size is 1024. If not specified, it will generate a key of 3072 bits.

Option -b to specify the number of bits in key
Option -b to specify the number of bits in key

You should use the default location to store SSH keys to avoid having to enter the path when connecting to SSH with keys.

If you don’t want to encrypt your key with a passphrase, press Enter to forgive.

Copy the key to the remote server

Now, the article has created a new SSH key pair and now needs to upload it to the remote computer that you want to manage.

The most efficient way to do this is to use the . command ssh-copy-id. Use the following command:

ssh-copy-id [email protected]_IP

If you are using a keyfile with its own filename, you can use the following command to specify the path to the keyfile.

ssh-copy-id -i ~/.ssh/id_rsa [email protected]_IP

If you are logging into the remote machine for the first time, you will need to accept the fingerprint.

Next, enter the SSH password for the remote user.

Once authenticated, the command ssh-copy-id will concatenate the contents of the key id_rsa.pub into file “~/.ssh/authorized_keys” on the remote machine and close the connection.

Copy the key to the remote server
Copy the key to the remote server

Log in to the remote machine

Once you have completed all the above steps, you can now log in to the remote server without a password.

You can check this using the command:

ssh [email protected]_ip

Unless you’ve enabled a passphrase for your key, you’ll be automatically signed in.

Hope you are succesful.

.

#Set #SSH #Linux

Related Posts

Leave a Reply

Your email address will not be published.

Close Bitnami banner
Bitnami