Ubuntu啟動自動登錄並啟動程序


最近在研究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   
 
Java代碼
  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  
Java代碼
  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.   
  6. [xdmcp]  
  7.   
  8. [gui]  
  9.   
  10. [greeter]  
Java代碼
  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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM