CentOS8中怎么设置SSH密钥(centos8,ssh,开发技术)

时间:2024-04-28 15:31:05 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

环境

客户端:CentOS8 192.168.43.137

服务端:CentOS8 192.168.43.139

创建SSH公私钥

通过输入以下命令,生成新的4096位的SSH密钥对:

[root@localhost~]#ssh-keygen-trsa-b4096Generatingpublic/privatersakeypair.Enterfileinwhichtosavethekey(/root/.ssh/id_rsa):Enterpassphrase(emptyfornopassphrase):Entersamepassphraseagain:Youridentificationhasbeensavedin/root/.ssh/id_rsa.Yourpublickeyhasbeensavedin/root/.ssh/id_rsa.pub.Thekeyfingerprintis:SHA256:ycOtSDK8ud2kd6EH7OxoQuc1BFb1HJ3T/kvAQJt0LrIroot@localhost.localdomainThekey'srandomartimageis:+---[RSA4096]----+|...oo.oo||o.+=.+.||...+=.o||.o.oo.o.||+.oSE...||.*..=o...||.oo.+o+...||.oo==o.||.o+ooo|+----[SHA256]-----+

CentOS8中怎么设置SSH密钥

想要验证是否生成了新的SSH密钥对,使用ls -l命令查看~/.ssh目录是否有刚才生成的文件:

[root@localhost~]#ll~/.ssh/total8-rw-------1rootroot3389May1308:26id_rsa-rw-r--r--1rootroot752May1308:26id_rsa.pub

CentOS8中怎么设置SSH密钥

将公钥复制到远程服务器,使用ssh-copy-id实用程序,输入远程服务器的root密码:

[root@localhost~]#ssh-copy-idroot@192.168.43.139/usr/bin/ssh-copy-id:INFO:Sourceofkey(s)tobeinstalled:"/root/.ssh/id_rsa.pub"Theauthenticityofhost'192.168.43.139(192.168.43.139)'can'tbeestablished.ECDSAkeyfingerprintisSHA256:7O1oIOooh5NZG87aC3v1Zz/vcTXkjOhQBnlkY0CD4y0.Areyousureyouwanttocontinueconnecting(yes/no)?yes/usr/bin/ssh-copy-id:INFO:attemptingtologinwiththenewkey(s),tofilteroutanythatarealreadyinstalled/usr/bin/ssh-copy-id:INFO:1key(s)remaintobeinstalled--ifyouarepromptednowitistoinstallthenewkeysPassword:Numberofkey(s)added:1Nowtryloggingintothemachine,with:"ssh'root@192.168.43.139'"andchecktomakesurethatonlythekey(s)youwantedwereadded.

CentOS8中怎么设置SSH密钥

也可以使用以下命令复制公钥:

[root@localhost.ssh]#cat~/.ssh/id_rsa.pub|sshroot@192.168.43.139"mkdir-p~/.ssh&&chmod700~/.ssh&&cat>>~/.ssh/authorized_keys&&chmod600~/.ssh/authorized_keys"

使用密钥登录服务器

使用以下命令登录ssh服务器:

[root@localhost~]#ssh192.168.43.139Lastlogin:TueMay1212:33:412020from192.168.43.137
CentOS8中怎么设置SSH密钥
在CentOS8中设置SSH密钥在CentOS8中设置SSH密钥

关闭密码认证

登录服务器端,关闭密码认证:

[root@localhost~]#ssh192.168.43.139Lastlogin:TueMay1212:33:412020from192.168.43.137[root@localhost~]#vim/etc/ssh/sshd_config搜索一下三条,将选项改为NoPasswordAuthenticationnoChallengeResponseAuthenticationnoUsePAMno

CentOS8中怎么设置SSH密钥

重启sshd服务:

[root@localhost~]#systemctlrestartsshd
 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:CentOS8中怎么设置SSH密钥的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:Linux下常用的命令有哪些下一篇:

19 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18