本文最后更新于:2023年12月5日 下午

SSH 登录安全又方便,但是输密码很不方便,本文记录密钥SSH登录的方法流程。

实验环境

  • 登录机器 Windows
  • 被登录机器 Ubuntu

操作流程

生成私钥公钥

1
ssh-keygen
  • 在ssh路径下得到 id_rsaid_rsa.pub

Linux 下在 ~/.ssh 文件夹

Windows 在 C:/Users/Administrator/.ssh/ 目录下

将公钥放在 authorized_keys 中

  • 公钥文件 id_rsa.pub
  • 将文件内容复制到 authorized_keys

配置 config 文件

  • .ssh 文件夹下编辑 config 文件
  • 加入内容:
1
2
3
4
5
6
Host omv
HostName 192.168.1.111
User vvd
Port 22
IdentityFile ~\.ssh\id_rsa
IdentitiesOnly yes

密钥访问ssh

  • 在终端执行:
1
2
3
4
5
6
7
8
9
10
11
$ ssh omv
Linux omv 5.10.0-0.bpo.9-amd64 #1 SMP Debian 5.10.70-1~bpo10+1 (2021-10-10) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue Feb 8 23:20:25 2022 from 192.168.1.4
vvd@omv:~$
  • 即可免密安全登录 ssh 终端

参考资料



文章链接:
https://www.zywvvd.com/notes/system/linux/ssh-identify-file/ssh-identify-file/


“觉得不错的话,给点打赏吧 ୧(๑•̀⌄•́๑)૭”

微信二维码

微信支付

支付宝二维码

支付宝支付

ssh 设置密钥认证登录
https://www.zywvvd.com/notes/system/linux/ssh-identify-file/ssh-identify-file/
作者
Yiwei Zhang
发布于
2022年2月8日
许可协议