ubuntu18.04 LTS
是笔者使用得最多的Linux发行版。本文记录一些小技巧已备自己参考。
更改时区
sudo dpkg-reconfigure tzdata
更改hostname
(1) sudo vim /etc/hostname
(2) sudo vim /etc/cloud/cloud.cfg
preserve_hostname: true # 第15行 false改成true
(3) 重启系统
sudo免输入密码
sudo vim /etc/sudoers
...
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
<你的用户名> ALL=NOPASSWD: ALL ## 添加此行 ###
...
开机自动运行脚本
(1) 编写systemd
相关脚本
sudo vim /etc/systemd/system/rc-local.service
内容如下:
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
(2) 编写启动脚本
sudo vim /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
赋予可执行权限: sudo chmod 755 /etc/rc.local
(3) 启用
sudo systemctl daemon-reload
sudo systemctl enable rc-local.service