How to Set Up and Use SSH in Linux

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 openssh-server package in the Software Center or the 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 and activate 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' .

How to Set Up and Use SSH in Linux Picture 1

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 ssh-keygen utility to interactively generate SSH key pairs. Use the -t option 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.

How to Set Up and Use SSH in Linux Picture 2

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 skip.

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 ssh-copy-id command . 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 ssh-copy-id command will append the contents of the id_rsa.pub key to the '~/.ssh/authorized_keys' file on the remote machine and close the connection.

How to Set Up and Use SSH in Linux Picture 3

Log in to the remote machine

Once you have completed all the above steps, you should now be able to login 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.

3.7 ★ | 3 Vote

May be interested

  • 10 reasons to switch to Linux right in 201210 reasons to switch to Linux right in 2012
    some people 'denigrate' the diversity of linux to cause fragmentation problems, but in fact this is one of the best strengths of linux. users have numerous linux distributions (distros) to choose from, whether it's mint or ubuntu, which is top-notch, or fedora with a variety of features for businesses and especially security.
  • What is Puppy Linux? Everything you need to know about Puppy LinuxWhat is Puppy Linux? Everything you need to know about Puppy Linux
    a linux distro that can run on virtually any computer with minimal configuration and computing resources is puppy linux.
  • The 5 most awaited things in Linux in 2019The 5 most awaited things in Linux in 2019
    linux has improved a lot in the past few years. some people who are not knowledgeable about technology have moved from windows to linux and responded very positively to this operating system.
  • How does the Linux Kernel work?How does the Linux Kernel work?
    the linux kernel is like a bridge that allows computing communication between applications and hardware, as well as managing the system's resources.
  • How to Learn LinuxHow to Learn Linux
    learning linux is not a one day task but it isn't herculean either. linux can be a good and safe os for both home and enterprise level users. keep in mind before saying 'hey, i'm going to start working on linux from tomorrow' that there is...
  • What do you know about Linux distros?What do you know about Linux distros?
    linux has existed for nearly 30 years, this is a historic journey. if you are interested in the history of some of the major linux distributions, read the following article.
  • 8 small utilities for a better Linux experience8 small utilities for a better Linux experience
    linux is one of the most flexible operating systems you can use today. from the interface to the internal functions, you can customize almost everything on your linux pc.
  • 7 ways to run Linux software on Windows7 ways to run Linux software on Windows
    linux users want to run windows software on linux, whereas windows users want to use linux software. even if you are looking for a better development environment, more powerful command-line tools, you can run linux software without removing windows.
  • From today, owning Linux LPI certificate will be easier!From today, owning Linux LPI certificate will be easier!
    lpi (linux professional institute), a world leader in international linux certification for open source professionals, has officially entered the vietnamese market.
  • The 5 best Linux server distributionsThe 5 best Linux server distributions
    linux is one of the factors driving the ever-evolving internet platform today. in fact, more than 70% of all websites are powered by unix, of which linux accounts for 58%.