列: 配置192.168.223.131免密传输到192.168.223.135
1.在131/135liunx下输入
ssh-keygen -t rsa
[root@localhost .ssh]# 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:
SHA256:O8nLEZ2VZsDJsI0oWC0u0ve926zNR1293//csPorOdg root@localhost.localdomain
The key's randomart image is:
+---[RSA 3072]----+
| .. .+.. |
| o. .. ++. . |
| ...... o . = .|
|. o o. . = o|
| . o . .S o . ..|
| ...+ . .. |
| *. + .. o|
| ..O. E ++|
| =o=..=+.B|
+----[SHA256]-----+
完成之后会在root目录下生成一个隐藏的.ssh文件并在这个文件夹下生成id_rsa和id_rsa.pub文件
[root@localhost ~]# ll -a .
drwx------. 2 root root 57 6月 17 10:13 .ssh
/*进入里面会发发现生成两个文件*/
[root@localhost .ssh]# ll
总用量 12
-rw-------. 1 root root 2622 6月 17 10:13 id_rsa
-rw-r--r--. 1 root root 580 6月 17 10:13 id_rsa.pub
-rw-r--r--. 1 root root 177 6月 17 10:03 known_hosts
2.将131主机下的id_rsa.pub文件通过scp传输到135下面并重命名为authorized_keys
其中只要这一次输入密码,以后通过scp传输就不需要输入密码
[root@localhost .ssh]# scp id_rsa.pub root@192.168.223.135:/root/.ssh/authorized_keys
root@192.168.223.135's password:
id_rsa.pub
注意:
在传输前要确保135主机上也有.ssh文件夹,如果没有可以手动创建或者通过 ssh-keygen -t rsa指令创建然后在把里面的内容删除
/这里使用的是第二个方案,推崇第二个,因为这样创建出来的文件也是隐藏的/
[root@localhost ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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:
SHA256:WL5QJMlnleRxVZ+2gITLI5AksliezgpKCHdzTo5GkVM root@localhost.localdomain
The key's randomart image is:
+---[RSA 3072]----+
| ...o=E..o=o.....|
|.oo.++oooooo. o|
|o.+ +.+o+ o. . o.|
|o+ o B * + o .|
|o.o o = S . . |
|+. . . . |
|o . |
| |
| |
+----[SHA256]-----+
[root@localhost ~]#
[root@localhost ~]# ll -a
总用量 48
dr-xr-x---. 4 root root 185 6月 16 22:14 .
dr-xr-xr-x. 17 root root 224 6月 16 21:20 ..
-rw-------. 1 root root 1029 6月 16 21:22 anaconda-ks.cfg
-rw-r--r--. 1 root root 12892 6月 16 22:03 b
-rw-r--r--. 1 root root 18 5月 11 2019 .bash_logout
-rw-r--r--. 1 root root 176 5月 11 2019 .bash_profile
-rw-r--r--. 1 root root 176 5月 11 2019 .bashrc
-rw-r--r--. 1 root root 100 5月 11 2019 .cshrc
drwxr-xr-x. 2 root root 23 6月 16 21:36 java
-rw-------. 1 root root 231 6月 16 21:57 .mysql_history
drwx------. 2 root root 38 6月 16 22:14 .ssh
-rw-r--r--. 1 root root 129 5月 11 2019 .tcshrc
-rw-------. 1 root root 1556 6月 16 21:36 .viminfo
[root@localhost ~]# cd .ssh
[root@localhost .ssh]# ll
总用量 8
-rw-------. 1 root root 2610 6月 16 22:14 id_rsa
-rw-r--r--. 1 root root 580 6月 16 22:14 id_rsa.pub
[root@localhost .ssh]# rm id_rsa
rm:是否删除普通文件 'id_rsa'?y
[root@localhost .ssh]# rm id_rsa.pub
rm:是否删除普通文件 'id_rsa.pub'?y
[root@localhost .ssh]# ll
总用量 0
