Ubuntu启动自动登录并启动程序

2023-02-18,,,

最近在研究Ubuntu,需要在系统启动之后自动登录,并且启动某个程序

手上拿到的系统只有一个空桌面,其他嘛也没有,鼠标右键也不管用。于是借助自己的虚拟机研究发现,自动启动程序配置文件在:

/home/username/.config/autostart下,并以.desktop命名。

比如我做了一个例子。

/home/henry/.config/autostart/mystartup.desktop内容如下:

    [Desktop Entry]
    Type=Application
    Encoding=UTF-8
    Version=1.0
    Name=No Name
    Name[en_US]=MyStartup
    Comment[en_US]=Try to start my programe
    Comment=Start the ...
    Exec=/home/henry/mysh.sh
    X-GNOME_Autostart-enabled=true

 

    [Desktop Entry]
    Type=Application
    Encoding=UTF-8
    Version=1.0
    Name=No Name
    Name[en_US]=MyStartup
    Comment[en_US]=Try to start my programe
    Comment=Start the ...
    Exec=/home/henry/mysh.sh
    X-GNOME_Autostart-enabled=true

配置好后,在系统-首选项-会话这个配置页面中就可以看到这个新添加的启动程序项目。

/home/henry/mysh.sh

    #!/bin/bash
    /usr/bin/gnome-system-monitor
    #!/bin/bash
    /usr/bin/gnome-system-monitor

这里启动了系统监视器。

上面工作做好后,重新启动系统,登录,就会看到系统监视器被启动起来。

Ubuntu提供了指定用户自动登录的功能,设置好后不需要用户输入密码,直接进入X环境。

配置是在系统-管理-登录窗口,在Security标签页中有Enable Automatic Login项,选中并指定用户即可。


个是GDM的配置,GDM的配置文件是在/etc/gdm/下,有gdm.conf(GDM的默认配置项,不要手动修改)和gdm.conf-
custom(自定义GDM配置),使用sudo
gdmsetup命令即可打开上面说的(系统-管理-登录窗口)配置界面。当在界面上进行修改后,可以打开gdm.conf-custom文件查看,能够
发现相关内容已经改变。

比如在我这里我直接手动修改gdm.conf-custom内容为:

    [daemon]
    AutomaticLoginEnable=true
    AutomaticLogin=henry
    [security]
    [xdmcp]
    [gui]
    [greeter]
    [daemon]
    AutomaticLoginEnable=true
    AutomaticLogin=henry
    [security]
    [xdmcp]
    [gui]
    [greeter]

保存并重新启动,系统自动登录并启动了系统监视器。
总结

作为程序员,不免要根据用户需求针对某些操作系统进行一些设置,这些设置需要直接修改配置文件,所以要定位好配置文件。

Ubuntu的自动启动的配置文件在用户目录下.config/autostart文件夹中,以.desktop命名的文件。

Ubuntu的自动登录的配置文件是/etc/gdm/gdm.conf-custom。

[Desktop Entry]
Encoding=UTF-8
Version=0.9.4
Type=Application
Name=player
Comment=start player demo
Exec=/home/player/start_app.sh
StartupNotify=false
Terminal=false
Hidden=false

Ubuntu启动自动登录并启动程序的相关教程结束。

《Ubuntu启动自动登录并启动程序.doc》

下载本文的Word格式文档,以方便收藏与打印。