这个方法的副作用就是只有root才能使用sftp!

创建用户组,创建用户,设置密码:- groupadd SSHTunnel

  • useradd -g SSHTunnel -s /bin/bash -d /home/tunnel TunnelUser1
  • passwd TunnelUser1复制代码设置sftp权限:- chmod 700 /usr/lib/openssh/sftp-server复制代码在/etc/ssh/sshd_config内添加:- Match Group SSHTunnel
  • AllowTcpForwarding yes
  • ForceCommand sh /home/tunnel/tunnelshell.sh复制代码下载设置登陆脚本:- wget https://chencp.info/tunnelshell.sh --no-check-certificate -O /home/tunnel/tunnelshell.sh
  • ln -s /home/tunnel/tunnelshell.sh /home/tunnel/.profile复制代码最后重启sshd:- /etc/init.d/ssh restart复制代码这样就可以了,同时用户登陆后还支持passwd命令修改密码。

再添加用户则:- useradd -g SSHTunnel -s /bin/bash -d /home/tunnel

  • passwd 复制代码