SSH配置外网连接内网
1. 实验室服务器A用户创建(用户名自己取)
# 创建用户zs
adduser zs
# 设置密码
sudo passwd zs
2. 腾讯云服务器B用户创建(用户名自己取)
# 创建用户zhangsan
adduser zhangsan
# 设置密码
sudo passwd zhangsan
3. A-->B设置免密登录
在A机器进行操作
#ssh秘钥分发错误“/usr/bin/ssh-copy-id: ERROR: No identities found”
# 生成公钥即可
cd ~
ssh-keygen
# 在A机器的公钥拷贝到B机器
ssh-copy-id zhangsan@111.111.111.111
# 为A机器的目录设置权限,必不可少
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa
在B机器进行操作
# 为B机器的目录设置权限,必不可少
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh
验证是否成功
ssh zhangsan@111.111.111.111
4.用 autossh 建立稳定隧道
在A机器进行操作
centos7 上没有默认安装autossh的,所以使用一下命令安装
sudo apt install autossh
命令
autossh -M 7281 -fCNR 7280:localhost:22 zhangsan@111.111.111.111
# 检查是否启动
ps aux | grep ssh
在B机器进行操作
ssh -fCNL *:1234:localhost:7280 localhost
# 检查是否启动
ps aux | grep ssh
5. 使用ssh登录
A机器名字:zs;B机器名字:zhangsan;监听端口:1234
ssh -p1234 zs@111.111.111.111
# 输入A机器用户的登录密码
问题解决
2021-2-6报错:channel 2: open failed: administratively prohibited: open failed
解决方法:
ssh -fCNL *:1234:localhost:7280 localhost
# 改为
ssh -fCNL *:1234:127.0.0.1:7280 127.0.0.1

浙公网安备 33010602011771号