服务器配置 ssh 密钥登录

服务器配置 ssh 密钥登录

配置 服务器安全组策略,开放 ssh 22 端口,以 root 用户登录服务器。

配置 ssh key 登录

  1. ssh-keygen 生成公钥和私钥对

  2. 如果不需要其他设置,一直回车

  3. 可以在 ~/.ssh 目录下看到两个文件,即刚生成的私钥 id_rsa 和 公钥 id_rsa.pub(具体名称取决于你的命名)

  4. 将公钥文件上传到服务器

    ssh-copy-id -i ~/.ssh/id_rsa.pub song@ip

  5. 在本地的 ~/.ssh/config 文件中加入以下配置

    shell 复制代码
    Host test # 改为任意名 之后需要使用 ssh test 登陆服务器
      HostName ip # 服务器 ip
      User root # 用户名
      IdentityFile /Users/user/.ssh/id_rsa
  6. ssh root@ip 登录

其他机器登录

id_rsa 放置到 ~/.ssh 目录下,在 config 中加入配置,使用 ssh root@ip 登录

禁止 ssh 密码登录

shell 复制代码
sudo vi /etc/ssh/sshd_config

# 允许root登录,但是禁止root密码登录
PermitRootLogin prohibit-password

#禁用密码验证
PasswordAuthentication no
#启用密钥验证
PubkeyAuthentication yes

# 重启服务
service ssh restart

# 注意
RSAAuthentication yes 是初代ssh协议,大部分系统已经废除,不建议开启。
相关推荐
砖厂小工21 小时前
用 GLM + OpenClaw 打造你的 AI PR Review Agent — 让龙虾帮你审代码
android·github
程序员鱼皮21 小时前
又一个新项目完结,我要出海了!
ai·github·开源项目
徐小夕1 天前
pxcharts-vue:一款专为 Vue3 打造的开源多维表格解决方案
前端·vue.js·github
Moment1 天前
想要长期陪伴你的助理?先从部署一个 OpenClaw 开始 😍😍😍
前端·后端·github
我叫黑大帅1 天前
前端如何利用 GitHub Actions 自动构建并发布到 GitHub Pages?
前端·面试·github
YuMiao1 天前
gstatic连接问题导致Google Gemini / Studio页面乱码或图标缺失问题
服务器·网络协议
HelloGitHub1 天前
这个年轻的开源项目,想让每个人都能拥有自己的专业级 AI 智能体
开源·github·agent
刘发财1 天前
弃用html2pdf.js,这个html转pdf方案能力是它的几十倍
前端·javascript·github
sunny8652 天前
Claude Code 跨会话上下文恢复:从 8 次纠正到 0 次的工程实践
人工智能·开源·github