首先,需要在debian9中开启开机自启服务,创建/etc/rc.local,填写: #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. exit 0 运行命令: chmod +x /etc/rc.local赋予执行权限 systemctl start rc-local启动服务 这样,我们只需要将需要执行的命令写在/etc/rc.local的exit 0前面,就可以在开机后自动执行。