在您的authorized_keys 文件中,您可以指定登录时将运行的命令。您可以简单地设置该命令来运行一些将等待很长时间的东西。sshd 手册页作为您可以在authorized_keys 文件中使用的所有选项的列表。
permitopen="tsserver.example.org:3389",no-pty,no-agent-forwarding,no-X11-forwarding,command="/usr/local/stm_shell.sh" ssh-rsa AAAAB3....
Run Code Online (Sandbox Code Playgroud)
我的 stm_shell.sh 就是这个(它还强制执行 12 小时超时)。我不是 100% 确定这是否完全安全。
#!/bin/bash
# send a hang-up after this process exits
shopt -s huponexit
# maximum session length in hours
CONNECT_TIME=12
sleep $[CONNECT_TIME*60]
kill $PPID
Run Code Online (Sandbox Code Playgroud)