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	

版权声明:本文为u011775882原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。