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

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
相关推荐
i建模1 天前
通过命令行使用密钥登录远程SSH主机
运维·ssh
wd5205212 天前
常用环境部署(二十九)——Centos升级OpenSSH 10.2p1
linux·运维·centos·ssh
深念Y2 天前
光猫改桥接模式实战:通过Telnet获取超级管理员密码
ssh·路由器·桥接模式·逆向·光猫·telent·管理员密码
徒 花3 天前
ubuntu远程连接ssh及VSCode配置远程ssh连接ubuntu
vscode·ubuntu·ssh
闲猫3 天前
Java ApacheSSHD实现SSH代理
运维·服务器·ssh
zhougl9963 天前
配置SSH免密
网络·ssh·php
鹓于3 天前
手机SSH直连电脑运行iflow终极安全配置
windows·安全·ssh
梦醒过后说珍重3 天前
【踩坑记录】局域网使用 mDNS 免 IP 登录服务器,却被代理 Fake-IP 劫持的排查过程
ssh
IMPYLH4 天前
Linux 的 basename 命令
linux·运维·服务器·ssh·bash
曦云沐4 天前
从零开始:OpenClaw 安全远程访问完全指南(SSH隧道实战版)
安全·ssh·openclaw