1. 创建一个新用户
使用以下命令创建一个新用户tcpuser。
sudo adduser tcpuser
你将需要为该用户设置密码并填写一些基本信息(可以跳过不重要的信息)。
2. 为了确保tcpuser没有高权限,首先要确保它不在sudo组里。使用以下命令来检查并删除该用户的sudo权限:
sudo deluser tcpuser sudo
3. 配置SSH只允许TCP转发
编辑/etc/ssh/sshd_config:
sudo nano /etc/ssh/sshd_config
在文件末尾添加以下配置:
Match User tcpuser
AllowTcpForwarding yes
PermitTunnel no
X11Forwarding no
GatewayPorts no
ForceCommand /bin/false
说明:
AllowTcpForwarding yes:允许该用户进行TCP转发。
PermitTunnel no:禁止网络隧道创建。
X11Forwarding no:禁止X11图形界面转发。
GatewayPorts no:不允许其他外部主机使用该用户的端口。
ForceCommand /bin/false:阻止用户在SSH连接中执行任何其他命令,只允许TCP转发。
4. 修改完成后,重启SSH服务使更改生效:
sudo systemctl restart ssh


