Linux怎麼添加使用者成為sudoers

來源:互聯網
上載者:User

有時候我們執行sudo的時候,出現

xxx is not int the sudoers file


告訴我們目前使用者不是sudoer,所以我們要把目前使用者添加進去,步驟如下:

1 修改/etc/sudoers檔案,進入超級使用者,因為沒有寫入權限,所以要先把寫入權限加上chmod u+w /etc/sudoers。

2 編輯/etc/sudoers檔案,找到這一 行:"root ALL=(ALL) ALL"在起下面添加"zhc ALL=(ALL) ALL"(這裡的zhc是你的使用者名稱),然後儲存。

3 最後恢複沒有寫入權限模式,撤銷檔案的寫入權限,chmod u-w /etc/sudoers。


然後我們就可以用zhc使用者來編輯root的檔案了,比如

vi /etc/sysconfig/network-scripts/ifcfg-eth0

修改後,不能直接儲存,因為沒有許可權,所以我們可以執行

:w !sudo tee %


這個命令將當前的緩衝區內容輸入到stdin,然後tee命令從標準輸入到標準輸出然後還有一個分流到檔案,這裡%代指當前檔案。

原文:http://blog.csdn.net/hongchangfirst/article/details/9044591

作者:hongchangfirst

hongchangfirst的首頁:http://blog.csdn.net/hongchangfirst

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.