linux免密登录

138 阅读1分钟
[root@localhost ~]# ssh-keygen -t ecdsa
Generating public/private ecdsa key pair.
Enter file in which to save the key (/root/.ssh/id_ecdsa):     //密钥存放目录,默认家目录
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):      //不设置密码,直接回车
Enter same passphrase again: 	               //不设置密码,直接回车
Your identification has been saved in /root/.ssh/id_ecdsa.
Your public key has been saved in /root/.ssh/id_ecdsa.pub.
The key fingerprint is:                          //不设置密码,直接回车
SHA256:5L7C6hZYwzaDsD0ouZaTAwkvGw2nP3fd12tMS/xCsa0 root@localhost.localdomain
The key's randomart image is:
+---[ECDSA 256]---+
|                 |
|+ .              |
|.& o    .        |
|@ * B  o      .  |
|o*o= + .S.   o + |
|o*+ o ... . . B .|
|. oo +  .  . = = |
|    . o  .    E .|
|   oo. ..    . . |
+----[SHA256]-----+


[root@localhost ~]# cd /~/.ssh    //移动到 用户的 .ssh文件夹下

[root@localhost .ssh]# ssh-copy-id -i /root/.ssh/id_ecdsa.pub root@192.168.84.200        //传输密钥到客户机上
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_ecdsa.pub"
The authenticity of host '192.168.84.200 (192.168.84.200)' can't be established.
ECDSA key fingerprint is SHA256:IDDghOrPUcw1fx9V1UZcKL0I23z6QkZiBOVc4kp4Fgw.
ECDSA key fingerprint is MD5:a5:2e:eb:35:17:25:50:53:27:63:54:7a:da:c8:8d:75.
Are you sure you want to continue connecting (yes/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.84.200's password:        //在此输入服务端的密码

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.84.200'"
and check to make sure that only the key(s) you wanted were added.



在客户机上 输入 
    ssh 需登录机器IP地址   
即可免密登录