欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

Linux配置远程SSH无密码登录

程序员文章站 2022-03-22 11:12:20
本文实例为大家分享了jalinux配置远程ssh无密码登录的方法,供大家参考,具体内容如下 系统:centos 6.8 主机1:192.168.0.177 主机2:1...

本文实例为大家分享了jalinux配置远程ssh无密码登录的方法,供大家参考,具体内容如下

系统:centos 6.8
主机1:192.168.0.177
主机2:192.168.0.178
工具介绍:
ssh-keygen:创建公钥和密钥
ssh-copy-id:把生成的公钥复制到192.168.0.178主机上的authorized_keys文件上,
ssh-copy-id也会给远程主机的用户主目录(/home)和/root/.ssh和/root/.ssh/authorized_key设置合适的权限

1)创建公钥和密钥

[root@test ~]# 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:
79:a9:66:cd:1a:a5:7c:82:80:c3:06:ec:44:13:b9:7a root@test
the key's randomart image is:
+--[ rsa 2048]----+
| +o |
|o.. |
|.o. |
|o+ . . . |
|..= . s + |
|..e. . o b |
| . . o + |
| o = |
| . |
+-----------------+

Linux配置远程SSH无密码登录

[root@test ~]#

2)拷贝公钥到远程主机

[root@test ~]# ls .ssh/
authorized_keys id_rsa id_rsa.pub
[root@test ~]#
[root@test ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.0.178
the authenticity of host '192.168.0.178 (192.168.0.178)' can't be established.
rsa key fingerprint is 53:bd:d7:e6:27:96:f3:70:f1:4b:4d:35:a4:38:1d:69.
are you sure you want to continue connecting (yes/no)? yes
warning: permanently added '192.168.0.178' (rsa) to the list of known hosts.
root@192.168.0.178's password:
now try logging into the machine, with "ssh 'root@192.168.0.178'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
[root@test ~]#

3)测试远程连接

[root@test ~]# ip addr show
1: lo: <loopback,up,lower_up> mtu 65536 qdisc noqueue state unknown
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state up qlen 1000
link/ether 00:0c:29:7e:1f:f6 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.177/24 brd 192.168.0.255 scope global eth0
inet6 fe80::20c:29ff:fe7e:1ff6/64 scope link
valid_lft forever preferred_lft forever
[root@test ~]#
[root@test ~]# ssh 192.168.0.178
last login: sat sep 24 14:00:49 2016 from 192.168.0.103
[root@test ~]#ip addr
1: lo: <loopback,up,lower_up> mtu 65536 qdisc noqueue state unknown
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state up qlen 1000
link/ether 00:0c:29:36:93:06 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.178/24 brd 192.168.0.255 scope global eth0
inet6 fe80::20c:29ff:fe36:9306/64 scope link
valid_lft forever preferred_lft forever

查看192.168.0.177生成的authorized_keys

[root@test .ssh]# cat authorized_keys
ssh-rsa aaaab3nzac1yc2eaaaabiwaaaqea+i6lxde5dvsmqjcx98fpzscxogpj6fd47yxzp/tp/htpotqgnbitjh6s6ynmsd5lqlbed8a5ctx5wkm+h7rt0po2xd+azcf69js+4swo8/xfwhlz/8o64hsvn68gmxqo9vp8giwwczny/csmoecllob1nfxpcwq1tbw+p4n84oj2yhwdszgcre8j/oiachhl6qhftaufvodvryfeyurfm8kp6bb6teeddrqilboaqttjowrd2fkt33c5lpuznngqc+dmrjdabgc3zgzrce3oyybharlfiwvhfpyt7pdqmnrp/dumybss/6gwd2cik3cv4zvpozygdynpqxsxiibikw== root@test

到此信任添加就完成了,192.168.0.177就可以无密码远程登录192.168.0.178服务器了,如果要想实现双向信任请在192.168.0.178
重复以上步骤,写本文目的只是想把会的东西记录下来,以备遗忘之时查阅!

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。