配置密钥
生成公钥
最好指定密钥文件名,默认是在 ~/.ssh 下面
1 | ssh-keygen -t rsa -b 4096 -C "xxx@xxx.com" -f ~/downloads/key |
私钥权限必须是 600
1 | chmod 600 ~/downloads/* |
上传公钥
1 | ssh-copy-id -i ~/downloads/key.pub root@192.168.56.11 |
服务器上公钥的保存路径
1 | # /etc/ssh/sshd_config |
用私钥连接
1 | ssh -i ~/downloads/key root@192.168.56.11 |
免密登陆
启动 agent
1 | eval "$(ssh-agent -s)" |
~/.profile
1 | if ! pgrep -u "$USER" ssh-agent > /dev/null; then |
连接
1 | # 连接服务器 A |
指纹更新
服务器无法登录,提示 fingerprint 更新
删除 ~/.ssh/known_hosts
或者
1 | ssh-keygen -R $SERVER_IP:$SERVER_PORT |
autossh
本地隧道
原来需要远程访问的服务,变为本地访问的服务
TARGET_IP 和 VPS_IP 可以不相同
1 | autossh -M 0 -i ./keys/id_rsa \ |
把服务转发给其它机器
1 | autossh -M 0 -i ./keys/id_rsa \ |
远程 gui
远程 ssh 执行 gui,在本地显示
远程机器
1 | # linux |
本地
1 | ssh -YC xxx@xx.xx.xx.xx |