CentOS8中怎么设置SSH密钥
导读:本文共2037字符,通常情况下阅读需要7分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: 环境客户端:CentOS8 192.168.43.137服务端:CentOS8 192.168.43.139创建SSH公私钥通过输入以下命令,生成新的4096位的SSH密钥对:[root@localhost~]#ssh-keygen-trsa-b4096Generatingpublic/privatersakeypair.Enterfileinwhichtos... ...
音频解说
目录
(为您整理了一些要点),点击可以直达。环境
客户端: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]-----+
想要验证是否生成了新的SSH密钥对,使用ls -l
命令查看~/.ssh目录是否有刚才生成的文件:
[root@localhost~]#ll~/.ssh/total8-rw-------1rootroot3389May1308:26id_rsa-rw-r--r--1rootroot752May1308:26id_rsa.pub
将公钥复制到远程服务器,使用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.
也可以使用以下命令复制公钥:
[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
关闭密码认证
登录服务器端,关闭密码认证:
[root@localhost~]#ssh192.168.43.139Lastlogin:TueMay1212:33:412020from192.168.43.137[root@localhost~]#vim/etc/ssh/sshd_config搜索一下三条,将选项改为NoPasswordAuthenticationnoChallengeResponseAuthenticationnoUsePAMno
重启sshd服务:
[root@localhost~]#systemctlrestartsshd
</div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:
CentOS8中怎么设置SSH密钥的详细内容,希望对您有所帮助,信息来源于网络。