windows免密ssh访问主机

基本步骤参考:SSH免密登录

cmd分别执行下面三条指令:

SET REMOTEHOST=remote-host-user@remote-host-ip
scp %USERPROFILE%\.ssh\id_rsa.pub %REMOTEHOST%:~/tmp.pub
ssh %REMOTEHOST% "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat ~/tmp.pub >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys && rm -f ~/tmp.pub"

如果指定了主机ssh端口, 在scp后面需要加上 -P port。ssh后面需要加上 -p port。

结果:

SET REMOTEHOST=remote-host-user@remote-host-ip
scp -P port %USERPROFILE%\.ssh\id_rsa.pub %REMOTEHOST%:~/tmp.pub
ssh -p port %REMOTEHOST% "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat ~/tmp.pub >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys && rm -f ~/tmp.pub"

ps:

remote-host-user:远程登录用户,一般都是root

remote-host-ip:远程主机IP

port:远程主机端口

更多阅读

分类:
|  标签 :
0 0 vote
Article Rating
Subscribe
提醒
guest
0 评论
Inline Feedbacks
View all comments