Linux系列:Ubuntu/fedora实用小技巧—禁止自动锁屏、设置免密码自动登录、免密码执行sudo操作...
生活随笔
收集整理的這篇文章主要介紹了
Linux系列:Ubuntu/fedora实用小技巧—禁止自动锁屏、设置免密码自动登录、免密码执行sudo操作...
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
首先聲明:該文雖以Ubuntu 13.04為例,同樣適用于Fedora 17(已測(cè)試),但在較低版本的Ubuntu下可能有所差異,具體看后面的注意事項(xiàng)。
技巧目錄:
解決方案:
(1)打開系統(tǒng)設(shè)置,找到“Brightness & Lock”(亮度和鎖屏)設(shè)置并打開,如下圖:
(2)根據(jù)提示可以設(shè)置屏幕多久關(guān)閉和鎖屏?xí)r間設(shè)定,一個(gè)“Never”和“OFF”即可搞定。
這樣設(shè)置后屏幕就不會(huì)自動(dòng)關(guān)閉和自動(dòng)鎖屏了。
解決方案:
(1)系統(tǒng)設(shè)置里找到“User Accounts”
(2)然后點(diǎn)擊右上角的“Unlock”,輸入當(dāng)前用戶的密碼解鎖認(rèn)證
(3)解鎖成功后,開啟自動(dòng)登錄功能,即“Automatic?Login”開關(guān)打開,保存設(shè)置即可。
注意事項(xiàng):較低版本的Ubuntu可能沒有該設(shè)置選項(xiàng),那么可以通過配置文件設(shè)置自動(dòng)登錄:
在/etc/gdm/目錄下有個(gè)custom.conf或者gdm.conf或gdm.conf-custom文件,比如我的Ubuntu9.11下的gdm下有這些文件:
打開gdm.conf-custom,截取最前面的幾句注釋說明如下: # GDM Configuration Customization file. # # This file is the appropriate place for specifying your customizations to the # GDM configuration. If you run gdmsetup, it will automatically edit this # file for you and will cause the daemon and any running GDM GUI programs to # automatically update with the new configuration. Not all configuration # options are supported by gdmsetup, so to modify some values it may be # necessary to modify this file directly by hand. # # Older versions of GDM used the "gdm.conf" file for configuration. If your # system has an old gdm.conf file on the system, it will be used instead of # this file - so changes made to this file will not take effect. Consider # migrating your configuration to this file and removing the gdm.conf file. 文件中后面說到如果有g(shù)dm.conf老配置文件,那么該文件中的值就不會(huì)起作用。那么我們就去gdm.conf里配置吧,打開后找到下面這一段: [daemon] # Automatic login, if true the first attached screen will automatically logged # in as user as set with AutomaticLogin key. AutomaticLoginEnable=false AutomaticLogin= 上面的意思很好理解,將AutomaticLoginEnable變量值改為true就可以了。
當(dāng)然,通過上面的提示我們知道還有一種方法修改該配置文件,就是使用sudo gdmsetup這個(gè)命令,運(yùn)行后會(huì)出現(xiàn)設(shè)置界面,進(jìn)入“Security”選項(xiàng)卡:
將“Enable?Automatic?Login“選上,然后選擇你自己的用戶名即可。
# This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a sudoers file. # Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"# Host alias specification# User alias specification# Cmnd alias specification# User privilege specification root ALL=(ALL:ALL) ALL# Members of the admin group may gain root privileges
默認(rèn)情況我們會(huì)看到有"root??? ALL=(ALL:ALL) ALL"這么一句話,意思就是root用戶可以從任何主機(jī)連接進(jìn)來以任意身份執(zhí)行任意命令,但是需要輸入密碼,如果不想輸入密碼只要在后面的ALL之前加 上NOPASSWD即可,關(guān)于該文件的格式及參數(shù)詳解請(qǐng)看參考文獻(xiàn)或運(yùn)行"man sudoers"看幫助文檔吧。下面直接給出方法吧:
如果想讓hadoop用戶使用sudo不用輸入密碼只要在該文件后面添加"hadoop ALL = NOPASSWD: ALL"這樣一行即可。 如果想讓 hadoop用戶sudo不用密碼即可執(zhí)行某幾個(gè)命令,可這樣寫"hadoop ?ALL = NOPASSWD: /usr/bin/abc.sh, /usr/sbin/adduser"。
技巧目錄:
- 解決Ubuntu下每隔幾分鐘自動(dòng)鎖屏,需要重新輸入密碼的問題
- 無須輸入用戶名密碼讓Ubuntu自動(dòng)登錄到桌面
- Ubuntu下如何使用sudo不用輸入密碼
1. 解決Ubuntu下每隔幾分鐘自動(dòng)鎖屏,需要重新輸入密碼的問題
有時(shí)候幾分鐘不用Ubuntu,系統(tǒng)就自動(dòng)鎖屏了,這是一種安全措施,防止別人趁你不在時(shí)使用你的系統(tǒng)。但對(duì)于大部分人而言,這是沒有必要的,尤其是Ubuntu虛擬機(jī),里面沒啥重要的東西,每次鎖屏后需要重新輸入密碼解鎖實(shí)際上非??菰锴依速M(fèi)時(shí)間。解決方案:
(1)打開系統(tǒng)設(shè)置,找到“Brightness & Lock”(亮度和鎖屏)設(shè)置并打開,如下圖:
(2)根據(jù)提示可以設(shè)置屏幕多久關(guān)閉和鎖屏?xí)r間設(shè)定,一個(gè)“Never”和“OFF”即可搞定。
這樣設(shè)置后屏幕就不會(huì)自動(dòng)關(guān)閉和自動(dòng)鎖屏了。
2. 無須輸入用戶名密碼讓Ubuntu自動(dòng)登錄到桌面
每個(gè)Linux用戶都必須設(shè)有密碼,這與Windows不同,對(duì)于非專業(yè)使用Linux的用戶來說,已經(jīng)解決了自動(dòng)鎖屏輸密 碼問題,如果每次登錄系統(tǒng)也不用輸入密碼 ,豈不是讓我們的工作更加輕松更加easy。注意這里的免密碼登錄系統(tǒng)并不是說用戶沒有密碼了,密碼還在只是系統(tǒng)把密碼記住了自動(dòng)用你的密碼登錄而已。解決方案:
(1)系統(tǒng)設(shè)置里找到“User Accounts”
(2)然后點(diǎn)擊右上角的“Unlock”,輸入當(dāng)前用戶的密碼解鎖認(rèn)證
(3)解鎖成功后,開啟自動(dòng)登錄功能,即“Automatic?Login”開關(guān)打開,保存設(shè)置即可。
注意事項(xiàng):較低版本的Ubuntu可能沒有該設(shè)置選項(xiàng),那么可以通過配置文件設(shè)置自動(dòng)登錄:
在/etc/gdm/目錄下有個(gè)custom.conf或者gdm.conf或gdm.conf-custom文件,比如我的Ubuntu9.11下的gdm下有這些文件:
打開gdm.conf-custom,截取最前面的幾句注釋說明如下: # GDM Configuration Customization file. # # This file is the appropriate place for specifying your customizations to the # GDM configuration. If you run gdmsetup, it will automatically edit this # file for you and will cause the daemon and any running GDM GUI programs to # automatically update with the new configuration. Not all configuration # options are supported by gdmsetup, so to modify some values it may be # necessary to modify this file directly by hand. # # Older versions of GDM used the "gdm.conf" file for configuration. If your # system has an old gdm.conf file on the system, it will be used instead of # this file - so changes made to this file will not take effect. Consider # migrating your configuration to this file and removing the gdm.conf file. 文件中后面說到如果有g(shù)dm.conf老配置文件,那么該文件中的值就不會(huì)起作用。那么我們就去gdm.conf里配置吧,打開后找到下面這一段: [daemon] # Automatic login, if true the first attached screen will automatically logged # in as user as set with AutomaticLogin key. AutomaticLoginEnable=false AutomaticLogin= 上面的意思很好理解,將AutomaticLoginEnable變量值改為true就可以了。
當(dāng)然,通過上面的提示我們知道還有一種方法修改該配置文件,就是使用sudo gdmsetup這個(gè)命令,運(yùn)行后會(huì)出現(xiàn)設(shè)置界面,進(jìn)入“Security”選項(xiàng)卡:
將“Enable?Automatic?Login“選上,然后選擇你自己的用戶名即可。
3. Ubuntu下如何使用sudo不用輸入密碼
普通用戶登錄Ubuntu一般使用的是普通賬戶而非管理員賬戶,因此運(yùn)行有管理員權(quán)限的程序時(shí)都要輸入sudo [command],這樣的命令輸入非常頻繁,關(guān)鍵是每次都要輸入一次用戶自己的密碼,非常煩人,下面就教你使用sudo不用輸入密碼的小技巧。
解決方案:
假設(shè)我的用戶名為hadoop,使用sudo不用密碼的方法如下:
運(yùn)行命令:sudo visudo 或者sudo vi /etc/sudoers,如果vi來編輯,則保存時(shí)記得用"wq!"強(qiáng)制保存,否則會(huì)提示只讀不能保存的。
上述命令就是用來編輯/etc/sudoers這個(gè)文件的。# This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a sudoers file. # Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"# Host alias specification# User alias specification# Cmnd alias specification# User privilege specification root ALL=(ALL:ALL) ALL# Members of the admin group may gain root privileges
默認(rèn)情況我們會(huì)看到有"root??? ALL=(ALL:ALL) ALL"這么一句話,意思就是root用戶可以從任何主機(jī)連接進(jìn)來以任意身份執(zhí)行任意命令,但是需要輸入密碼,如果不想輸入密碼只要在后面的ALL之前加 上NOPASSWD即可,關(guān)于該文件的格式及參數(shù)詳解請(qǐng)看參考文獻(xiàn)或運(yùn)行"man sudoers"看幫助文檔吧。下面直接給出方法吧:
如果想讓hadoop用戶使用sudo不用輸入密碼只要在該文件后面添加"hadoop ALL = NOPASSWD: ALL"這樣一行即可。 如果想讓 hadoop用戶sudo不用密碼即可執(zhí)行某幾個(gè)命令,可這樣寫"hadoop ?ALL = NOPASSWD: /usr/bin/abc.sh, /usr/sbin/adduser"。
注意:這里有個(gè)問題需要注意,就是后面的配置可能會(huì)覆蓋前面的配置,所以你添加的配置最好是在最后一行。
?
參考文獻(xiàn):
非常Linux——sudoers文件的寫法
轉(zhuǎn)載于:https://www.cnblogs.com/lanxuezaipiao/p/3617436.html
總結(jié)
以上是生活随笔為你收集整理的Linux系列:Ubuntu/fedora实用小技巧—禁止自动锁屏、设置免密码自动登录、免密码执行sudo操作...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: listbox icon
- 下一篇: 进程资源限制(rlimit)