Linux cancels the SSH login password

  

Sometimes we want to log in to SSH through another account, usually we need to re-enter the password when logging in. However, for some users who don't want to remember too many passwords, this is a bit of a hassle. How can I log in without entering a password?

Solution:

1. You need a user & ldquo; aliceA & rdquo; log on to the hostA.

2. Use ssh-keygen to generate a pair of rsa public and private keys. The generated key pair will be stored in the ~/.ssh directory.

$ ssh-keygen -t rsa

3. Use the following command to create the ~/.ssh directory under the aliceB user directory on the target host hostB. If the .ssh directory already exists on aliceB@hostB, this step will be skipped.

$ ssh aliceB@hostB mkdir -p .ssh

4. Copy the public key of user “aliceA” on hostA to aliceB@hostB to implement passwordless ssh.

$ cat .ssh/id_rsa.pub |  Ssh aliceB@hostB ‘cat 》 .ssh/authorized_keys’

Since then, you don't need to enter a password from ssh to aliceB@hostB on aliceA@hostA. (Small compilation Note: The above operation of creating a directory and copying can also be done in one step by an ssh-copy-id command: ssh-copy-id -i ~/.ssh/id_rsa.pub aliceB@hostB)

Troubleshooting

1. You may still need to enter your SSH password even after the key authentication is in effect. If this is the case, check the system log (such as /var/log/secure) to see if the following exception occurs.

Authentication refused: bad ownership or modes for file /home/aliceB/.ssh/authorized_keys

In this case, the key authentication failed due to the ~/.ssh/authorized_keys file The permissions or owner are incorrect. In general, this error occurs if the file is readable by all users except you. Change the permissions of the file in the following way to fix the error.

$ chmod 700 ~/.ssh/authorized_keys

The above is how to log in to the SSH server without entering a password in the Linux system. If you have a user who has encountered this situation, follow the above method to set it up.

Copyright © Windows knowledge All Rights Reserved