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