SSH那些事

ssh已经无处不在,尤其是ansible完全依赖于ssh实现了无agent管理机器。

发布自己的public key

自己电脑 —访问—》 远程电脑

自己电脑的public key —放到—> 远程电脑的.ssh/authorized_keys .

自己的public key:
自己生成:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jack/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/jack/.ssh/id_rsa.
Your public key has been saved in /home/jack/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:XNTbM9mTiyFhjgsMG0R/5+Ou6LrBprvlRcxzIfY7dWE jack@jack
The key's randomart image is:
+---[RSA 2048]----+
| oo .. |
| o. . o. |
| =+ o=..E o.|
| .+++o+oo.*o.|
| =So.+..ooo|
| . . o.+ o. . |
| = . o . |
| = o . o |
| +o++o ... |
+----[SHA256]-----+

$ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDsP6P3B6JNmkI2xFMXfNUe8LSQC+fWgB7ifNU7uS2iv55dPiU5uWo0LMLW9SQhVHQeFl9V5ur8t19rCY1IoMvQNoSfEnWjN2PTO2rhbugqBBwVQzZLkyqfLtiMGdSIzQ1CFvoHQbX3fb2A70GXpoX8pa2P5TP4WJufsLKEamcnIXhdW8GVQif9Gf24VCYyUn+Omi3RdWHOdn1gQsLB7qfapO/t4vSURHYvdgy0AJ2bmJRBqCKseIEBXsdNy3VbL1DxSTU8kww20nSV4wa9OPxPMApdzPIiXxx+ow70KvgwrfBnc8gQ6yxzdBnyGHizU0TLWv3FLO5ZtDz+6v77zeZX jack@jack

然后复制到远程主机的.ssh/authorized_keys文件里。

当然,也可以一句命令搞定:

1
cat ~/.ssh/id_rsa.pub | ssh USER@HOST "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

当然,还有个软件叫ssh-copy-id