两台linux机器之间互连
连接的命令及查看 w
<a href="https://s1.51cto.com/oss/201710/20/4ef831a69356da80cb3f4d2b8c99b441.png-wh_500x0-wm_3-wmp_4-s_1170928847.png" target="_blank"></a>
说明两个终端在连接 192.168.133.1 是windows 129是Alex2在连接
<a href="https://s1.51cto.com/oss/201710/20/06879a42f67e33f674a64dfcab96b572.png-wh_500x0-wm_3-wmp_4-s_2381243361.png" target="_blank"></a>
正确的写法
<a href="https://s1.51cto.com/oss/201710/20/1ffaa1f474370f31a103f82f2771a3ac.png-wh_500x0-wm_3-wmp_4-s_3940154153.png" target="_blank"></a>
查看当前登录的 whoami
<a href="https://s5.51cto.com/oss/201710/20/e400a5d73f4958840cc6ced9b00b350b.png-wh_500x0-wm_3-wmp_4-s_2035429298.png" target="_blank"></a>
[root@alex-01 ~]# ssh [email protected] 完整的写法
[root@alex-01 ~]# ssh -p 22 [email protected] 指定端口的写法
设置秘钥
<a href="https://s5.51cto.com/oss/201710/20/15c67c52146827d9918ab4e244ec3de8.png-wh_500x0-wm_3-wmp_4-s_1730322151.png" target="_blank"></a>
[root@alex-2 ~]# ssh-keygen 命令
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:
68:0d:16:73:5a:56:3d:80:4d:ab:17:3c:68:a6:0f:27 root@alex-2
The key's randomart image is:
+--[ RSA 2048]----+
| o +=+o |
| B.o..o |
| + + = . |
| . B . o |
| E S . |
| . = . |
| . |
| |
+-----------------+
[root@alex-2 ~]# ls /root/.ssh/ 查看公钥和私钥
authorized_keys id_rsa id_rsa.pub known_hosts
查看2的公钥
<a href="https://s4.51cto.com/oss/201710/20/73bb58807be089bbf44ac497e004d59d.png-wh_500x0-wm_3-wmp_4-s_2634147396.png" target="_blank"></a>
[root@alex-01 ~]# vi /root/.ssh/authorized_keys
<a href="https://s1.51cto.com/oss/201710/20/46e8f6e519c3929fb880961dcecaba90.png-wh_500x0-wm_3-wmp_4-s_340878706.png" target="_blank"></a>
添加进去
<a href="https://s1.51cto.com/oss/201710/20/3085a3c7f9e2657cf53224dda269d051.png-wh_500x0-wm_3-wmp_4-s_214464265.png" target="_blank"></a>
重启机器 了 看下selinux 有没启动 需要用getenforce 显示enforcing 证明selinux开启了 打开的
<a href="https://s3.51cto.com/oss/201710/20/9809202cc1412674e48da13efcef4f95.png-wh_500x0-wm_3-wmp_4-s_3973738587.png" target="_blank"></a>
临时关闭 setenforce 0
[root@alex-01 ~]# getenforce 在看状态
Permissive
<a href="https://s3.51cto.com/oss/201710/20/0b59a6f8445796cc9d0021ec23d8e89d.png-wh_500x0-wm_3-wmp_4-s_4133821889.png" target="_blank"></a>
成功免秘钥
<a href="https://s4.51cto.com/oss/201710/20/47edb6063a4ca60464567eea4ac886ed.png-wh_500x0-wm_3-wmp_4-s_2105172125.png" target="_blank"></a>
本文转自 amenging 51CTO博客,原文链接:http://blog.51cto.com/11335852/1974776