How to set an SSH password on Linux for passwordless login

不言
Release: 2019-03-14 14:35:05
Original
3768 people have browsed it

This article will introduce about setting up ssh key on Linux system. In a Linux system using ssh key pair, we can also say it is passwordless ssh.

How to set an SSH password on Linux for passwordless login

#ssh (secure shell) is widely used to log in to Linux servers remotely. When we log in to the remote system using ssh, it prompts for a password and then only allows us to log in to the server. Sometimes we need to configure an application or script (mainly shell script) to automate the tasks to be performed after ssh'ing to the remote system. However, if we do not configure key-based ssh, the script will prompt for a password every time it is run, and we will need to enter the password manually. To solve this problem, we can choose to use the public key/private key concept. Where the remote server allows other systems to ssh based on the key.

Step 1: Generate ssh key pair

First, you need to generate a key pair (rsa or dsa), you can use "- t" command line switch to specify the option rsa or dsa key. If you do not pass the -t parameter, it will create an RSA key by default.

$ ssh-keygen -t rsa
Copy after login
Generating public/private rsa key pair. Enter file in which to save the key (/home/rahul/.ssh/id_rsa): Created directory '/home/rahul/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/rahul/.ssh/id_rsa. Your public key has been saved in /home/rahul/.ssh/id_rsa.pub. The key fingerprint is: SHA256:GZQ3tJffEUimdMZHIG3LcpvdkOaogwXBtWeaM2ejzYY rahul@tecadmin The key's randomart image is: +---[RSA 2048]----+ | ..+oo+*+o | | .+ +o** ..| | .oooB oo | | .o B =+..| | S.= *+=.o| | .X.+...| | oE.+ | | . o. | | . | +----[SHA256]-----+
Copy after login

The above command will create two files in the ~/.ssh directory as shown below.

1、~/.ssh/id_rsa [Private Key]

2、~/.ssh/id_rsa.pub [Public Key]

Step 2: Copy the Public Key to the Remote System

Let’s copy the system’s public key to the key file of the remote system ~/.ssh/authorized_key. We can do this manually or using the ssh-copy-id command line tool.

$ ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.10.20
Copy after login

Output:

21 root@192.168.10.20's password: Now try logging into the machine, with "ssh '192.168.10.20'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting.
Copy after login

It will prompt for the password of the remote system. Enter the remote machine password and press Enter.

Step 3: Verify SSH without Password

Now that we are done, just try to ssh to the remote system. You will log into the remote system without entering a password.

$ ssh root@192.168.10.20
Copy after login

The above command will not prompt for the login password. In any case, if the ssh command prompts for a password, it means your setup is not configured correctly, please retry all steps.

This article has ended here. For more exciting content, you can pay attention to other related column tutorials on the php Chinese website! ! !

The above is the detailed content of How to set an SSH password on Linux for passwordless login. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
ssh
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!