服务器连接(ssh)简化指令 & 免密登录
一直都有这个需求,今天在朋友帮助下总算来学会了。以下是具体操作,没有什么代码解释,打码掉的内容用过 ssh 的朋友应该都懂。
Linux系统适用!!windows关于这个 bash 系统配置文件的问题我也不知道在哪,应该找到了的话其他操作都一样吧。
具体操作
vim .zshrc(默认是 bash,如果不知道 zsh 的用vim .bashrc应该不会出现问题)- 在.
zshrc文件中某一行加入alias name_you_want="ssh xxxxx@xxx.xxx.xxx.xxx -p xxxx",name_you_want就是你简化的指令。 :wq保存之后激活指令:source .zshrc(bash 同理)ssh-copy-id xxxxx@xxx.xxx.xxx.xxx -p xxxx(正常的连接服务器的格式,只是ssh变成了ssh-copy-id)- 好了之后就可以直接用
name_you_want指令免密连接了
成功标志
第四步成功之后会看到如下显示(用 x 替换数字和用户名了):
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/hugvgngj/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
kaiyuan@xxx.xxx.xxx.xxx's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh -p 'xxxx' 'xxxxx@xxx.xxx.xxx.xxx'"
and check to make sure that only the key(s) you wanted were added.