作者:该改改小心眼_222 | 来源:互联网 | 2020-07-29 16:46
本篇文章将介绍关于在Linux系统上设置ssh密钥。在使用ssh密钥对的Linux系统中,我们也可以说它是无密码的ssh。
首先,需要生成一个密钥对(rsa或dsa),可以使用“-t”命令行开关指定选项rsa或dsa密钥。如果不传递-t参数,它将默认创建RSA密钥。
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/rahul/.ssh/id_rsa):
Created directory '/home/rahul/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/rahul/.ssh/id_rsa.
Your public key has been saved in /home/rahul/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:GZQ3tJffEUimdMZHIG3LcpvdkOaogwXBtWeaM2ejzYY rahul@tecadmin
The key's randomart image is:
+---[RSA 2048]----+
| ..+oo+*+o |
| .+ +o** ..|
| .oooB oo |
| .o B =+..|
| S.= *+=.o|
| .X.+...|
| oE.+ |
| . o. |
| . |
+----[SHA256]-----+
上面的命令将在〜/ .ssh目录中创建两个文件,如下所示。
1、〜/ .ssh / id_rsa [私钥]
2、〜/ .ssh / id_rsa.pub [公钥]
步骤2:将公钥复制到远程系统
让我们将系统的公钥复制到远程系统〜/ .ssh / authorized_key的密钥文件中。我们可以手动或使用ssh-copy-id命令行工具执行此操作。
$ ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.10.20
输出:
21
root@192.168.10.20's password:
Now try logging into the machine, with "ssh '192.168.10.20'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
它将提示输入远程系统的密码。输入远程机器密码并按Enter。
步骤3:验证没有密码的SSH
现在我们已经完成了所有工作,只需尝试对远程系统进行ssh。你将在不输入密码的情况下登录远程系统。
$ ssh root@192.168.10.20
上面的命令不会提示输入登录密码。在任何情况下,如果ssh命令提示输入密码,则意味着你的设置没有正确配置,请重试所有步骤。
本篇文章到这里就已经全部结束了,更多其他精彩内容可以关注 第一PHP社区 的其他相关栏目教程!!!
以上就是如何在Linux上设置SSH密码以进行无密码登录的详细内容,更多请关注 第一PHP社区 其它相关文章!