设置SSH登陆快捷方式和proxy

一般登陆服务器,需要输入长长一条指令

ssh username@your_server_ip -p port

你可以使用 alias,但 SSH 本身也提供有相应的解决方案,在本地创建一个~/.ssh/config文件

nano ~/.ssh/config
Host your_server_name
HostName your_server_ip
User username
IdentityFile /Users/username/.ssh/id_rsa
Port 22

注意:IdentityFile是私钥位置
如果提示It is required that your private key files are NOT accessible by others. This private key will be ignored.
设置私钥只读
chmod 400 ~/.ssh/id_rsa
设置私钥可读写
chmod 600 ~/.ssh/id_rsa
以后登陆只需要输入ssh your_server_name

设置连接代理

有时因为某些众所周知的原因连接不上远程服务器,这时就需要在连接服务器时添加代理

Host your_server_name
HostName your_server_ip
ProxyCommand=nc -X 5 -x localhost:1080 %h %p
ServerAliveInterval   10
User zyu
IdentityFile /Users/username/.ssh/id_rsa
Port 22

ProxyCommand=nc -X 5 -x localhost:1080 %h %p注意host和端口号换成自己的。ServerAliveInterval 60表示每隔60s发送一个心跳检测,确保不会断开与远程连接

你可能感兴趣的:(设置SSH登陆快捷方式和proxy)