前提要上传公钥到服务器
第1步:生成密钥(如果之前已经生成了跳过这步)
cmd-命令行输入以下:获取公钥到本地生成
ssh-keygen -t ed25519
一路回车,不用填任何东西。
第2步:上传公钥到服务器
type C:\Users\Administrator\.ssh\id_ed25519.pub
目录C:\Users\Administrator\.ssh新建文件config
配置内容如下:
Host dashboard
HostName 207.60.2.94
Port 4122
User root
LocalForward 9119 127.0.0.1:9119
# 可选:保持长连、断线自动重连
ServerAliveInterval 30
ServerAliveCountMax 3
ExitOnForwardFailure yes
然后就可以直接:ssh dashboard
。。。。
cat ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
再检查 SSH 配置是否允许密钥登录:
grep -i “PubkeyAuthentication” /etc/ssh/sshd_config
如果显示
PubkeyAuthentication no,需要改成 yes:sed -i ‘s/PubkeyAuthentication no/PubkeyAuthentication yes/’ /etc/ssh/sshd_config
systemctl restart sshd
systemctl restart sshd
检查 authorized_keys 是否被重复追加导致格式错误
cat -A ~/.ssh/authorized_keys
然后回本地测试:ssh -p 端口 root@你的IP
应该就能免密登录了,
https://www.coze.cn/session/7646460796586918144
评论(0)
暂无评论