将本地密钥上传到这个实现免密登录

User: ssh -p 32703 root@connect.nmb1.seetacloud.com

将本地密钥上传到这个实现免密登录

GitHub Copilot: 按以下步骤做即可:

  1. 生成密钥(如果已存在可跳过)

    在 PowerShell 里执行:

    ssh-keygen -t ed25519 -C "your_email@example.com"

  2. 复制公钥内容

    在 PowerShell 里执行:

    Get-Content $env:USERPROFILE.ssh\id_ed25519.pub

  3. 上传到服务器(免密登录)

    执行:

    ssh -p 32703 root@connect.nmb1.seetacloud.com

    登录后执行:

    mkdir -p ~/.ssh ; chmod 700 ~/.ssh

    echo "粘贴上一步的公钥内容" >> ~/.ssh/authorized_keys

    chmod 600 ~/.ssh/authorized_keys

  4. 测试免密

    退出后再次执行:

    ssh -p 32703 root@connect.nmb1.seetacloud.com

如果你已有不同的公钥文件名(比如 id_rsa.pub),把第2步路径换成对应文件即可。

User: 你来操作

GitHub Copilot: Ran terminal command: Test-Path env:USERPROFILE.ssh\\id_ed25519.pub; Test-Path env:USERPROFILE.ssh\id_rsa.pub

已有 id_rsa.pub 密钥,现在读取公钥内容并上传到服务器:

Ran terminal command: $pubkey = Get-Content KaTeX parse error: Undefined control sequence: \id at position 21: ...SERPROFILE\.ssh\̲i̲d̲_rsa.pub; ssh -...pubkey' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys && echo 'Done!'"

需要输入密码才能完成上传。请输入服务器密码:

Ran terminal command

看起来命令被中断了。我用另一种方式来完成 - 先使用 ssh-copy-id 或者手动方式。让我用 type 命令通过管道上传:

Ran terminal command: type $env:USERPROFILE.ssh\id_rsa.pub | ssh -p 32703 root@connect.nmb1.seetacloud.com "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

公钥已成功上传!现在测试免密登录是否生效:

Ran terminal command: ssh -p 32703 root@connect.nmb1.seetacloud.com "echo '免密登录成功!' && hostname"

免密登录配置成功!

现在你可以直接使用以下命令登录服务器,无需输入密码:

复制代码
ssh -p 32703 root@connect.nmb1.seetacloud.com
相关推荐
芜湖xin16 小时前
【恒源智享云】pycharm社区版SSH方式使用实例
ssh·云服务器
corpse201017 小时前
VirtualBox 安装ubuntu-25 ,配置SSH工具登录
linux·ubuntu·ssh
Zhu7582 天前
【软件更新】在Ubuntu24 LTS中更新openssl到指定版本,例如openssl3.5.6 LTS
linux·ssh·ssl
有理想的打工人2 天前
gitlab群组管理与ssh链接
ssh·gitlab
杨云龙UP2 天前
从0到1快速学会Linux操作系统(基础),这一篇就够了!
linux·运维·服务器·学习·ubuntu·centos·ssh
小鸡食米2 天前
Linux-SSH
linux·运维·ssh
且_听_风_吟3 天前
SSH 连接 Gerrit老版本 失败问题复盘
运维·ssh
特别关注外国供应商4 天前
SSH PrivX™ OT 案例 - 某船舶运营商为数千艘船舶实现了远程访问,用于诊断、维护和物联网数据采集
物联网·ssh·数据采集·ad·远程访问·多因素身份验证·privx
仙俊红5 天前
关于ssh免密登录
运维·ssh
特别关注外国供应商5 天前
SSH 的 PrivX OT 工业安全远程访问 (ISRA) 被 分析机构 Industrial Cyber 认可
人工智能·网络安全·ssh·特权访问管理·工业安全远程访问·privx·ot 访问安全