Preparatory work:
1. Confirm the configuration file of native sshd (requires root permission)
$ gedit/etc/ssh/sshd_config
Find the following and remove the comment "#"
Rsaauthentication Yes
Pubkeyauthentication Yes
Authorizedkeysfile. Ssh/authorized_keys
2. If you modify the configuration file, you need to restart the sshd service (requires root permission)
$/sbin/service sshd Restart
Configuring SSH password-free login takes 3 steps:
1. Generate public and private keys
2. Import the public key to the authentication file, change the permissions
3. Testing
1. Generate public and private keys
Shell code: SSH-KEYGEN-T RSA
The default is to generate two files in the ~/.ssh directory:
Id_rsa: Private key
Id_rsa.pub: Public Key
2. Import the public key to the authentication file, change the permissions
2.1 Importing this machine
Shell code: Cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
2.2 Importing a server to password-free login
First copy the public key to the server
Shell code: SCP ~/.ssh/id_rsa.pub [Email protected]:/home/id_rsa.pub
Then, import the public key into the authentication file (this step is done on the server)
Shell code: Cat/home/id_rsa.pub >> ~/.ssh/authorized_keys
2.3 Changing permissions on the server
Shell code: chmod ~/.ssh
chmod ~/.ssh/authorized_keys
CentOS Setup ssh password-free login