ubuntu server 20.04 设置开机启动

需要root权限:可以sudo 但是我习惯直接su

su
passwd:

vim打开末尾添加几行:

vi /lib/systemd/system/rc-local.service
#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

# added by yourself
[Install]
WantedBy=multi-user.target
Alias=rc-local.service

保存退出。

把刚保存的文件链接到/etc/systemd/system/目录下:

ln -s /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service

打开 /etc/rc.local 输入:

vi /etc/rc.local
#!/bin/bash
autossh -M 8888 -NR 1234:localhost:22 [email protected] -p 22 &
exit 0

保存,退出,赋权限
chmod 755 /etc/rc.local

reboot

但是,重启后,启动时网络还没连接,导致该命令还是无法运行?还没验证。

你可能感兴趣的:(ubuntu server 20.04 设置开机启动)