首页 > 系统 > Linux > 正文

Linux配置远程SSH无密码登录

2019-11-02 16:18:20
字体:
来源:转载
供稿:网友

本文实例为大家分享了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 rsaGenerating 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@testThe key's randomart image is:+--[ RSA 2048]----+| +o ||o.. ||.o. ||o+ . . . ||..= . S + ||..E. . o B || . . O + || o = || . |+-----------------+

[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.178The 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)? YESWarning: 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_keysto make sure we haven't added extra keys that you weren't expecting.[root@test ~]#

3)测试远程连接

[root@test ~]# ip addr show1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWNlink/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host loinet6 ::1/128 scope hostvalid_lft forever preferred_lft forever2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:7e:1f:f6 brd ff:ff:ff:ff:ff:ffinet 192.168.0.177/24 brd 192.168.0.255 scope global eth0inet6 fe80::20c:29ff:fe7e:1ff6/64 scope linkvalid_lft forever preferred_lft forever[root@test ~]#[root@test ~]# ssh 192.168.0.178Last login: Sat Sep 24 14:00:49 2016 from 192.168.0.103[root@test ~]#ip addr1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWNlink/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host loinet6 ::1/128 scope hostvalid_lft forever preferred_lft forever2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:36:93:06 brd ff:ff:ff:ff:ff:ffinet 192.168.0.178/24 brd 192.168.0.255 scope global eth0inet6 fe80::20c:29ff:fe36:9306/64 scope linkvalid_lft forever preferred_lft forever
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表