How can I autologin to desktop with systemd?

This is described in the Arch Wiki:

Create a new service file similar to getty@.service by copying it to /etc/systemd/system/

cp /usr/lib/systemd/system/getty@.service /etc/systemd/system/autologin@.service

This basically copies the already existing getty@.service to a new file autologin@.service which can be freely modifed. It is copied to /etc/systemd/system because that's where site-specific unit files are stored. /usr/lib/systemd/system contains unit files provided by packages so you shouldn't change anything in there.

You will then have to symlink that autologin@.service to the getty service for the tty on which you want to autologin, for examply for tty1:

ln -s /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service`

Up to now, this is still the same as the usual getty@.service file, but the most important part is to modify the autologin@.service to actually log you in automatically. To do that, you only need to change the ExecStart line to read

ExecStart=-/sbin/agetty -a USERNAME %I 38400

The difference between the ExecStart line in getty@.service and autologin@.service is only the -a USERNAME which tells agetty to log the user with the username USERNAME in automatically.

Now you only have to tell systemd to reload its daemon files and start the service:

systemctl daemon-reload
systemctl start getty@tty1.service

(I'm not sure if the service will start properly if you're already logged in on tty1, the safest way is propably to just reboot instead of starting the service).

If you then want to automatically start X, insert the following snippet into your ~/.bash_profile(taken from the wiki again):

if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then
    exec startx
fi

You will have to modify your ~/.xinitrc to start your desktop environment, how to do that depends on the DE and is probably described in the Arch wiki as well.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值