最近在研究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
