更新 CentOS 账号秘钥

  1. 通过子账号登入系统
  2. 创建密钥对
[username@devicename ~]$ ssh-keygen -t rsa -C "20230912"   # -C参数为备注,方便自己辨识

Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):   # 回车,默认路径

Created directory '/home/username/.ssh'.
Enter passphrase (empty for no passphrase):   # 回车,默认空密码

Enter same passphrase again:   # 回车,默认空密码

Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
  1. 打开新生成的id_rsa.pub公钥,复制里面的内容
  2. 在新密钥文件的相同目录下找到 authorized_keys 文件,将公钥内容全部覆盖到该文件内
  3. 下载新生成的id_rsa私钥,此私钥可用于远程 SSH 登录(注意要开放登录端口)
posted @ 2023-09-12 14:50  西湖摸鱼  阅读(47)  评论(0编辑  收藏  举报