1. Generate the key.
The Ssh-keygen command is used to generate key pairs, basic options:
- -t specifies the key type (RSA,RSA1,DSA,ECDSA).
- -p Specifies the passphrase.
- -f Specifies the name of the generated key file.
- -C Add a comment.
-T rsa-f key-p 123456 #创建文件名为key, the cipher is 123456, and the type is a key pair of RSA. A total of two files, where key is the private key, Key.pub is the public key.
2. Deploy the public key to Linux and download the private key to local.
cat key.pub >> ~/. ssh/authorized_keys #如果没有. SSH directory, to be created first. (mkdir. SSH)
chmod ~/.ssh/authorized_keys #修改权限.
The download key can use the SZ command or the SCP command or the FileZilla software.
3. Modify the configuration file (/etc/ssh/sshd_config).
Open the following configuration.
Rsaauthentication Yes #开启密钥登录
Pubkeyauthentication Yes
Authorizedkeysfile. Ssh/authorized_keys #公钥存放地方
Permitrootlogin Yes # allows root login----to open according to actual needs
Passwordauthentication no #禁止密码登录----open according to actual needs
4. Restart the SSH service.
sudo service sshd restart
Note: If the SSH link fails, you can check the SSH log to find out why the link failed.
[Email protected] ~]# cd/var/log/ Less secure #用空格翻页, the last is the latest record.
Linux Key Login