SSH 的无密码自动登录

一实验环境

MAC 主机上安装Wmware Fusion ,运行了一台Linux主机。 MAC和Fusion之间是桥接模式。 MAC的地址为10.1.195.148, 虚拟机的IP为 10.1.195.193 

二  步骤 

1  在本地主机生成RSA 公钥和私钥。命令为

ssh-keygen -t rsa

这里选择的加密类型为RSA ,程序会提示你输入口令,这里不输入也可以生成密钥,但是这样安全性没有保障。

pingMacBook-Pro:~ ping$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/ping/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 

输入口令后提示生成密钥成功

Your identification has been saved in /Users/ping/.ssh/id_rsa.
Your public key has been saved in /Users/ping/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:V+9pjPA42kncpJrRewzW/bkOltiEWx5543kawvkiNwE ping@pingMacBook-Pro.local
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|                 |
|            .    |
|          E....  |
|        S o+.*.o |
|         +oOX=*.o|
|        ..B=BB*+o|
|         B.+B+.+o|
|        + ++ o+o.|
+----[SHA256]-----+

  生成的秘钥默认保存在  ~/.ssh 文件夹里,里面有俩个文件,其中 id_rsa.pub 为公钥, id_rsa 为私钥

2   将公钥上传到远程主机 

  使用的命令为 ssh-copy-id

pingMacBook-Pro:.ssh ping$ ssh-copy-id ping@10.1.195.148 
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/ping/.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
ping@10.1.195.148's password: 

Number of key(s) added:        1

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

这里会要求输入生成秘钥时候的口令

3  验证

pingMacBook-Pro:.ssh ping$ ssh  ping@10.1.195.148 
Enter passphrase for key '/Users/ping/.ssh/id_rsa': 
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Sun Jan 19 03:25:51 2020 from 10.1.195.193

只要输入口令,就可以登录成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值