1. 程式人生 > 其它 >linux設定祕鑰登入

linux設定祕鑰登入

1、在linux伺服器生成公鑰和私鑰

[root@localhost .ssh]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in
/root/.ssh/id_rsa.pub. The key fingerprint is: 02:54:da:3a:4e:d4:21:44:9c:f6:47:22:db:50:71:77 [email protected] The key's randomart image is: +--[ RSA 2048]----+ | +=+=.. . E | | .*=.o.. . | | .+*oo | | ..oo . | | + ..S | | o . . | | . | | | | | +-----------------+

2、配置檔案開啟祕鑰登入

cat/etc/ssh/sshd_config

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

systemctl restart sshd

3、建立認證檔案

touch .ssh/authorized_keys
chmod 700 .ssh/authorized_keys
cat .ssh/id_rsa.pub >> .ssh/authorized_keys

4、將.ssh/id_rsa下載到win客戶端

通過Xshell等工具將祕鑰匯入

選擇匯入祕鑰登入即可