Ubuntu22.04系统
编辑getty配置文件
vim /etc/systemd/system/getty@tty1.service.d/override.conf
如果该目录或者文件不存在,进行创建。
在override.conf文件中进行编辑:
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin yourusername --noclear %I $TERM
退出编辑并保存文件
重新加载systemd配置
sudo systemctl daemon-reload
sudo systemctl restart getty@tty1.service
最后可重启机器测试自动登录
Ubuntu18.04和Ubuntu16.04系统
编辑getty文件
vim /etc/systemd/system/getty@tty1.service.d/override.conf
如果该目录或者文件不存在,则需要创建
在override.conf文件中进行编辑:
[Service]
ExecStart=
ExecStart=-/sbin/agetty --noissue --autologin root %I $TERM
Type=idle
自动测试脚本
在根目录.profile中添加自动测试脚本/root/.profile
TTYCount=`tty | grep tty1 | wc -l`
if [[ $TTYCount -eq 1 ]]; thenautotest.sh
fi