[root@jxy ~]# 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:ZSUvsGzRvMMxtCoVYdaeAMiMSRp1tUoPFgQhtnxlyeE root@jxy
The key's randomart image is:
+---[RSA 2048]----+
|o+=O=*=.B*o . |
|o++.B+ =.=*= |
|.o .+E. =+==. |
| .o + o +*. |
| . o S . |
| . |
| |
| |
| |
+----[SHA256]-----+
[root@jxy ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.93.130
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.93.130's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.93.130'"
and check to make sure that only the key(s) you wanted were added.
[root@server ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
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:qFMtqZTZ47GJaG0HiJd1cD8WETQruz32ZUrNkAOk1eo root@server
The key's randomart image is:
+---[RSA 2048]----+
| . ..O+ |
| o = +. |
| . + *. |
| . + = B.o . |
|. + = X.S + |
| . + B OE = |
| o B * + . = |
| . . o . + + |
| o |
+----[SHA256]-----+
[root@server ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.93.129
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.93.129 (192.168.93.129)' can't be established.
ECDSA key fingerprint is SHA256:tUKn1O7OhpHFIfvdqnOiqpo9c7B/oMA+6lMUKPPkmgk.
ECDSA key fingerprint is MD5:da:0c:74:cd:41:4e:35:ab:55:04:ba:ac:fd:f2:52:56.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.93.129's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.93.129'"
and check to make sure that only the key(s) you wanted were added.
[root@jxy ~]# ssh root@192.168.93.130
Last login: Tue Jul 2 09:17:48 2019 from 192.168.93.1
[root@server ~]#
[root@jxy ~]# cd .ssh/
[root@jxy .ssh]# ls
id_rsa id_rsa.pub known_hosts known_hosts.gz
使用 ssh-copy-id 将公钥复制到远程系统上的正确位置
root@jxy .ssh]# ls
id_rsa id_rsa.pub known_hosts known_hosts.gz
[root@jxy .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.93.130
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.93.130's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.93.130'"
and check to make sure that only the key(s) you wanted were added.
[root@jxy .ssh]# ssh root@192.168.93.130
Last login: Mon Jul 1 11:38:23 2019 from 192.168.93.129
[root@server ~]# cd .ssh/
[root@server .ssh]# ll
总用量 8
-rw-------. 1 root root 390 7月 1 11:39 authorized_keys
-rw-r--r--. 1 root root 187 3月 30 22:38 known_hosts.gz
使用 ssh 命令无命令登录远程主机
[root@jxy ~]# ssh root@192.168.93.130
Last login: Mon Jul 1 11:43:41 2019 from 192.168.93.129
[root@server ~]# ip a s eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:0c:0c:44 brd ff:ff:ff:ff:ff:ff
inet 192.168.93.130/24 brd 192.168.93.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe0c:c44/64 scope link
valid_lft forever preferred_lft forever
使用 scp 命令传送文件到远程主机
[root@jxy ~]# scp 99.sh root@192.168.93.130:/tmp
99.sh 100% 117 91.3KB/s 00:00
[root@jxy ~]# ssh root@192.168.93.130
Last login: Mon Jul 1 11:43:48 2019 from 192.168.93.129
[root@server ~]# cd /tmp
[root@server tmp]# ls
99.sh
使用 scp 命令从远程主机上下载文件到本地
[root@jxy ~]# ls
99.sh 1
[root@jxy ~]# ls
1
[root@jxy ~]# scp root@192.168.93.130:/tmp/99.sh .
99.sh 1 100% 117 30.6KB/s 00:00
[root@jxy ~]# ls
99.sh
使用 ssh-keygen 创建公钥-私钥对[root@jxy ~]# 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): En...