SSH passwordless login(免密登陆)

linux,windows 都一样。

下面以windows为例:

生成密钥对

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/user/.ssh/id_rsa): ./id_rsa_ss1
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in ./id_rsa_ss1.
Your public key has been saved in ./id_rsa_ss1.pub.
The key fingerprint is:
SHA256:YgEqk6O7p8iQYc8Cxxxxxxxxxxzqu0UDCRkXeTJIDs user@DESKTOP-8LB6JPN
The key's randomart image is:
+---[RSA 3072]----+
|.=.o+o           |
|o.=o+..          |
...
...
|+.o o +          |
|++ .o+           |
+----[SHA256]-----+

加载私钥

$ ssh-add ./id_rsa_ss1
Could not open a connection to your authentication agent.

出现上面的错误时,Could not open a connection to your authentication agent

$ ssh-agent bash
$ ssh-add ./id_rsa_ss1
Identity added: ./id_rsa_ss1 (user@DESKTOP-8LB6JPN)

将公钥部署到需要登陆的设备

$ ssh-copy-id -i ./id_rsa_ss1.pub [email protected]    (或者 pscp id_rsa_ss1.pub [email protected]:~\.ssh\authorized_keys)
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "./id_rsa_ss1.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:


Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

免密登陆

$ ssh [email protected]
Last login: Fri Jul 24 12:39:36 2020 from xxx.xxx.xxx.xxx

Welcome to xxxx Cloud Elastic Compute Service !

你可能感兴趣的:(SSH passwordless login(免密登陆))