linux 使用root登錄后,使用root權限,用nohup后端運行程序,退出ssh后,程序被殺死
【原因】
新版的sshd服務,配置文件中,退出ssh后,默認配置會殺死當前控制組里面的所有子進程,修改策略即可
退出ssh的殺死程序(KillMode)有如下策略:
1、control-group(默認值):當前控制組里面的所有子進程,都會被殺掉
2、process:只殺主進程
3、mixed:主進程將收到 SIGTERM 信號,子進程收到 SIGKILL 信號
4、none:沒有進程會被殺掉,只是執行服務的 stop 命令。
【解決方法】
(1)、在 /lib/systemd/system/sshd@.service 配置文件的[Service]下追加KillMode=process
[Unit]
Description=OpenSSH per-connection server daemon
Documentation=man:sshd(8) man:sshd_config(5)
Wants=sshd-keygen.service
After=sshd-keygen.service
[Service]
EnvironmentFile=-/etc/sysconfig/sshd
ExecStart=-/usr/sbin/sshd -i $OPTIONS
KillMode=process #追加這個配置
StandardInput=socket
(2)、重啟sshd
systemctl restart sshd.service