[root@b04f945297ac .ssh]# ssh-keygen -t rsa -b 4096 Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/zhimma_id_rsa Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/zhimma_id_rsa. Your public key has been saved in /root/.ssh/zhimma_id_rsa.pub. The key fingerprint is: SHA256:WrIN4U/dk+1KdTxv0t5zFeXCeWWpvaNtFFMxbkDY2Cw root@b04f945297ac The key's randomart image is: +---[RSA 4096]----+ | Bo oo| | E +o.*| | . ..o*+| | . . . . +=*o| | + S . + o+B| | X + *+| | o o . * *| | . o Bo| | . . =| +----[SHA256]-----+
[root@b04f945297ac .ssh]# ls known_hosts zhimma_id_rsa zhimma_id_rsa.pub [root@b04f945297ac .ssh]#
放置公钥
ssh-copy-id
把公钥拷贝到需要登录的远程服务器或Linux系统上,这里可以使用ssh-copy-id
ssh-copy-id默认端口是22,如果要重新指定端口,则使用-p 端口号命令
1 2 3 4 5 6 7 8 9 10
[root@b04f945297ac .ssh]# ssh-copy-id -i /root/.ssh/zhimma_id_rsa.pub -p 203 root@192.168.2.107 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/zhimma_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.2.107's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh -p '203' 'root@192.168.2.107'" and check to make sure that only the key(s) you wanted were added.
这样就把公钥加的指定的服务器上了
尝试登陆下
1 2 3
[root@b04f945297ac .ssh]# ssh -i /root/.ssh/zhimma_id_rsa -p 203 root@192.168.2.107 Last login: Wed Jun 6 04:16:09 2018 from 172.17.0.1 [root@e91b4a662023 ~]#