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

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

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

比如我做了一个例子。

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

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

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

/home/henry/mysh.sh

  1. #!/bin/bash
  2. /usr/bin/gnome-system-monitor
  1. #!/bin/bash
  2. /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内容为:

  1. [daemon]
  2. AutomaticLoginEnable=true
  3. AutomaticLogin=henry
  4. [security]
  5. [xdmcp]
  6. [gui]
  7. [greeter]
  1. [daemon]
  2. AutomaticLoginEnable=true
  3. AutomaticLogin=henry
  4. [security]
  5. [xdmcp]
  6. [gui]
  7. [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

05-11 13:26