教程短文資訊

在 Ubuntu 終端中如何從root切換到其他用戶?

Ubuntu和任何其他Linux中,root用戶是超級用戶,非常重要,因為這個Linux用戶帳戶具有所有文件和服務訪問許可權。這就是為什麼不建議使用root用戶帳戶進行常規系統任務,因為它可能會帶來安全風險。除了使用root用戶之外,用戶可以創建一個具有有限訪問許可權和特權的單獨帳戶。

此外,在Ubuntu中,所有用戶都有唯一的用戶ID或UID和一組許可權,指定用戶可以在系統上執行的活動。 root用戶帳戶具有UID為0和對系統上所有文件和目錄的完全訪問許可權。在本教程中,我們將討論如何從Ubuntu發行版的root切換到另一個標準Linux用戶帳戶。

要從root用戶帳戶切換到另一個用戶帳戶,請按照以下步驟操作:

步驟1:打開Ubuntu終端

您可以在Ubuntu CLI伺服器或GUI桌面上,但要在終端中從root切換用戶帳戶,我們需要訪問它。因此,要麼SSH到遠程Ubuntu伺服器,要麼打開終端應用程序,如果使用圖形桌面,則快捷鍵是Ctrl+Alt+T

步驟2:檢查當前用戶

讓我們首先檢查您正在使用哪個用戶。嗯,如果您正在使用root,則已在終端提示符中以「username@hostname」的格式顯示。

但是,如果您仍然想確認一下,則可以使用給定的命令,然後按Enter鍵。輸出將顯示當前用戶名。

whoami

步驟3:從root切換到另一個Ubuntu用戶

如果您不知道除了Root之外還有哪些可用的用戶,則可以使用給定的命令列出所有用戶:

cat /etc/passwd | cut -d: -f1

該命令將列印所有用戶,包括那些與特定服務(如Apache、SQL等)相關聯的用戶。如果您不知道要切換到哪個用戶,請找到要切換的用戶。

或者,您可以僅列印標準登錄用戶,這些用戶通常具有從min-1000到max-60000的UID例如:

getent passwd {1000..2000}

一旦您有了要切換的用戶名,就使用給定的命令。

su - username

請注意,此命令中的「username」應替換為您想要切換到的用戶名。然後輸入該用戶的密碼,即可從root切換到該用戶。

步驟4:驗證新用戶

現在,您可以使用以下命令檢查當前用戶是否已更改為您剛剛切換到的用戶:

whoami

此命令將顯示您當前使用的用戶名。

步驟5:sudo訪問

如果您想以sudo身份運行某些命令,則可以使用以下命令:

sudo command

請注意,此命令中的「command」應替換為您要運行的實際命令。

步驟6:退出新用戶帳戶

要退出已切換到的用戶帳戶並返回root用戶,請輸入以下命令:

exit

通過這種方式,Ubuntu,尤其是默認使用root帳戶的伺服器用戶,可以切換到新的或現有的標準用戶,反之亦然。然而,在將用戶帳戶添加到sudo組之前,了解其用途是什麼是很重要的。

對這篇文章感覺如何?

太棒了
0
不錯
0
愛死了
0
不太好
1
感覺很糟
0

You may also like

5 Comments

  1. 350fairfax nordvpn promotion
    Great blog you’ve got here.. It’s hard to find excellent writing like yours nowadays.

    I really appreciate individuals like you! Take
    care!!

  2. I every time emailed this webpage post page
    to all my contacts, for the reason that if like to read
    it then my friends will too.

    my web page nordvpn coupons inspiresensation (http://92url.com/nordvpn-coupons-inspiresensation–71584)

  3. Attractive element of content. I just stumbled upon your blog and in accession capital to say that
    I get in fact enjoyed account your blog posts.
    Any way I’ll be subscribing in your feeds or even I achievement you access consistently fast.

    my web blog – nordvpn coupons inspiresensation

  4. Hurrah! After all I got a weblog from where I
    can really obtain useful data regarding my study and knowledge.

    Here is my site: nordvpn coupons inspiresensation, t.co,

  5. Hello, i feel that i noticed you visited my website thus i got here to go back the
    choose?.I’m attempting to to find things to improve my website!I assume its ok to use some of your ideas!!

    my web site :: nordvpn coupons inspiresensation

Leave a reply

您的郵箱地址不會被公開。 必填項已用 * 標註

這個站點使用 Akismet 來減少垃圾評論。了解你的評論數據如何被處理

More in:教程

教程

在 Ubuntu Linux 上安裝 Clang

無論您使用的是 Ubuntu 22.04、20.04 或其他任何版本,並且想要安裝 Clang(一個開源的 C、C++ 和 Objective-C 編譯器),本文將對您有所幫助。Clang 是 GNU […]