CentOS under SSH no password login configuration file

  • 2020-05-12 06:40:11
  • OfStack

1. Confirm the configuration file of local sshd (root permission is required)


$ gedit /etc/ssh/sshd_config

Find the following and remove the comment "#"


RSAAuthentication yes
  PubkeyAuthentication yes
  AuthorizedKeysFile .ssh/authorized_keys

2. If the configuration file is modified, the sshd service needs to be restarted (root permission is required).


$ /sbin/service sshd restart

Configuring SSH to login without a password takes three steps:

1. Generate public and private keys

2. Import the public key into the authentication file and change the permissions

3. The test

1. Generate public and private keys

Shell code: ssh-keygen-t rsa

By default, two files are generated in the ~/.ssh directory:

id_rsa: the private key
id_rsa. pub: public key

2. Import the public key into the authentication file and change the permissions

2.1 import the machine

Shell code: cat ~/.ssh/id_rsa.pub > > ~/.ssh/authorized_keys

2.2 import the server to which you want to log in without a password

First, copy the public key to the server

Shell code: scp ~/.ssh/id_rsa.pub xxx@host :/home/ id_rsa.pub

Then, import the public key into the authentication file (this 1 step takes place on the server)

Shell code: cat /home/ id_rsa.pub > > ~/.ssh/authorized_keys

2.3 change permissions on the server

Shell code: chmod 700 ~/.ssh

chmod 600 ~/.ssh/authorized_keys

3. Test ssh xxx


Related articles: