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

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
相关推荐
开发者联盟league5 天前
安装pnpm
ssh
2601_961875245 天前
决战申论100题2026|最新|范文
linux·容器·centos·debian·ssh·fabric·vagrant
小小小花儿6 天前
SSH密钥配置(免密连接远程服务器)
服务器·ssh
m0_526119406 天前
ssh key生成,gitee配置ssh
运维·gitee·ssh
qq_338432376 天前
VSCode Remote-SSH 远程 Windows Server 卡死的排查与解决
windows·vscode·ssh
着迷不白6 天前
十、网络客户端工具curl, wget, ssh, scp, sftp, rsync
运维·网络·ssh
江畔柳前堤6 天前
github实战指南01-账号配置与 SSH 密钥
运维·人工智能·深度学习·ssh·github·pyqt·信号处理
相醉为友7 天前
Trae IDE WSL2/SSH 环境网络故障排查笔记
ide·笔记·ssh
c238568 天前
git常见错误和ssh验证推送
运维·git·ssh
zh路西法8 天前
【tmux入门】终端分屏、SSH远程守护与一键启动脚本
linux·运维·ssh·bash