温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

linux远程登录ssh免密码怎么配置

发布时间:2022-03-23 16:00:44 来源:亿速云 阅读:161 作者:iii 栏目:web开发

这篇“linux远程登录ssh免密码怎么配置”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“linux远程登录ssh免密码怎么配置”文章吧。

一、情景

公司刚上几台linux,现在要把主机之间都能远程ssh免密码登陆。

二、原理
很简单,使用ssh-keygen 在主机a上生成private和public密钥,将生成的public密钥拷贝到远程机器主机b上后,就可以使用ssh命令无需密码登录到另外一台机器主机b上。

三、步骤

主机a:

1、 生成公钥和私钥文件id_rsa和id_rsa.pub (敲3下回车即可)
[root@bogon ~]# ssh-keygen -t rsa
generating public/private rsa key pair.
enter file in which to save the key (/root/.ssh/id_rsa):
enter passphrase (empty for no passphrase):
enter same passphrase again:
your identification has been saved in /root/.ssh/id_rsa.
your public key has been saved in /root/.ssh/id_rsa.pub.
the key fingerprint is:
67:da:0d:79:e0:d6:2b:cd:7d:22:af:51:7e:9c:75:fe root@bogon
the key's randomart image is:
+--[ rsa 2048]----+
| |
| |
| . |
| . + |
| s b o . o|
| * * = o+|
| . o b +.=|
| . + +.|
| ... e|
+-----------------+

2、ssh-cop-id命令会将指定的公钥文件复制到远程计算机

[root@bogon ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.1.250.166
the authenticity of host '10.1.250.166 (10.1.250.166)' can't be established.
rsa key fingerprint is c8:9d:6d:92:55:77:3d:3e:af:f5:cb:18:80:5a:47:93.
are you sure you want to continue connecting (yes/no)? yes
warning: permanently added '10.1.250.166' (rsa) to the list of known hosts.
reverse mapping checking getaddrinfo for bogon [10.1.250.166] failed - possible break-in attempt!
root@10.1.250.166's password: <主机b的登陆密码>
now try logging into the machine, with "ssh 'root@10.1.250.166'", and check in:

.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

3、然后ssh登陆主机b验证是否需要密码

[root@localhost ~]# ssh 10.1.250.166
reverse mapping checking getaddrinfo for bogon [10.1.250.166] failed - possible break-in attempt!
last login: wed oct 21 10:05:39 2015 from 10.1.250.141
[root@bogon ~]#

4、登陆成功后,我们需要在主机b也做下以上3步,这样就可以相互免密码ssh登陆。(如果有多台主机,每台主机都做下相同操作,以方便以后管理)。

5、权限问题
建议用其他用户做ssh登陆的话,调整目录文件权限
设置authorized_keys权限

chmod 644 authorized_keys

设置.ssh目录权限

chmod 700 -r .ssh

6、要保证.ssh和authorized_keys都只有用户自己有写权限。否则验证无效。

以上就是关于“linux远程登录ssh免密码怎么配置”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI