username@hostname:~# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa): // 这里输入要生成的文件名
Created directory '/home/username/.ssh'. // 这里输入密码
Enter passphrase (empty for no passphrase): // 这里重复输入密码
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:LIGNrf7jteWJtB6quaJgOwT4yLkbyIBhCTUOCW58Em0 /home/username/@hostname
The key's randomart image is:
+---[RSA 2048]----+
|=++ ||=ooE=||oBo.o + ||*.o . o ||=o. . . S ||=+.. . ||++. . + . ||oo+ o.+ B . ||.+o.+++o= o |+----[SHA256]-----+
免密登录
复制 A 机公钥到 B 机/home/username/.ssh 目录下的 authorized_keys 文件里。