教程短文资讯

在 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 […]