linux开通帐户_如何在Linux中确定当前用户帐户

linux开通帐户

linux开通帐户

Bash shell on Unity desktop concept
Fatmawati Achmad Zaenuri/Shutterstock.com Fatmawati Achmad Zaenuri / Shutterstock.com

If Linux means anything, it means choice. You can achieve even a simple task like identifying the current user in many ways. This tutorial will show you how to use some of the quickest and easiest methods.

如果Linux意味着任何东西,那就意味着选择。 您甚至可以完成许多简单的任务,例如以多种方式标识当前用户。 本教程将向您展示如何使用一些最快,最简单的方法。

Why would you need to find the identity of the current user? In many cases the owner of the computer is the only user and, without getting too existential, they probably know themselves. Perhaps, but it is also common for people to create additional user accounts to allow family members to have access to the computer. And, if you’re connected to a remote shell on a server somewhere, you may need a quick reminder of the username you’re logged in with. If you see a logged in session with no one in attendance, how do you identify the current user from the command line?

为什么需要查找当前用户的身份? 在许多情况下,计算机的所有者是唯一的用户,并且他们可能会认识自己,而不会太过于存在。 也许可以,但是人们创建额外的用户帐户以允许家庭成员访问计算机也是很常见的。 而且,如果您连接到某处服务器上的远程Shell,则可能需要快速提醒您登录时使用的用户名。 如果看到没有人出席的登录会话,如何从命令行中识别当前用户?

Let’s try the easiest option first. All we need to do is look at the command prompt. By default, Linux distributions have the username in the prompt. Simple. We didn’t even have to type a thing.

让我们首先尝试最简单的选项。 我们需要做的就是查看命令提示符。 默认情况下,Linux发行版在提示符下具有用户名。 简单。 我们甚至不必键入任何内容。

User name shown in command prompt

If the user has changed their prompt to some other format we need to try something else. The who command will give us the information we are looking for.

如果用户将提示更改为其他格式,我们需要尝试其他操作。 who命令将为我们提供所需的信息。

who
Output from the who command

The output from who gives you the name of the current user, the terminal they are logged in at, the date and time when they logged in. If it is a remote session, it also tell us where they are logged in from.

who提供的输出给您当前用户的名称,他们登录的终端,他们登录的日期和时间。如果是远程会话,它还会告诉我们他们从哪里登录。

By comparison, the whoami command provides a very pithy answer:

相比之下, whoami命令提供了一个非常精妙的答案:

whoami
Output from the whoami command

You can get the same one-word answer by echoing the $USER environment variable to the screen.

通过将$USER环境变量回显到屏幕上,可以得到相同的一词答案。

echo $USER
Using echo to display the user environment variable

The one-letter command w requires less typing and provides more information.

单字母命令w需要更少的键入并提供更多的信息。

w

Output from the w command

The w command provides us with the user name which is what we wanted, and a bonus set of data for that user. Note that if there are multiple users logged into the Linux system, the w command will list them all. You’d need to know which terminal the user you were interested in had logged in on. If they’ve logged directly onto the Linux computer itself, that’ll be pts/o, so look for :0 in the output from w .

w命令为我们提供了我们想要的用户名,以及该用户的额外数据集。 请注意,如果有多个用户登录到Linux系统,则w命令将列出所有用户。 您需要知道感兴趣的用户已登录哪个终端。 如果他们直接登录到Linux计算机本身,则将是pts / o,因此请在w的输出中查找:0。

The w command provides the boot time, uptime and average load for the previous five, ten and fifteen minutes, and the following information regarding the current user.

w命令提供了前五分钟,十分钟和十五分钟的启动时间,正常运行时间和平均负载,以及有关当前用户的以下信息。

  • USER: The user name.

    USER :用户名。

  • TTY: The type of terminal they are logged in at. This will usually be a pts (a pseudo-teletype). :0 means the physical keyboard and screen connected to this computer.

    TTY :他们登录的终端类型。 这通常是pts(伪电传)。 :0表示连接到此计算机的物理键盘和屏幕。

  • FROM: The name of the remote host if this is a remote connection.

    FROM :远程主机的名称(如果这是远程连接)。

  • LOGIN@: The time at which the user logged in.

    LOGIN @ :用户登录的时间。

  • IDLE: Idle time. This shows ?xdm? in the screenshot because we’re running under an X-windows Display Manager, which does not provide that information.

    空闲 :空闲时间。 这显示?xdm? 在屏幕快照中显示,因为我们在X-windows显示管理器下运行,该管理器不提供该信息。

  • JCPU: Joint CPU time, this is the CPU time used by all processes that have been attached to this tty. In other words, the total CPU time of this user in this logged in session.

    JCPU :联合CPU时间,这是已附加到该tty的所有进程使用的CPU时间。 换句话说,此用户在此登录会话中的总CPU时间。

  • PCPU: Process CPU time, this is the CPU time used by the current process. The current process is named in the WHAT column.

    PCPU :进程CPU时间,这是当前进程使用的CPU时间。 当前进程在WHAT列中命名。

  • WHAT: The command line of this user’s current process.

    内容 :此用户当前进程的命令行。

Now that we know who this user is, we can obtain more information about them. The id command is a good place to start. Type id, a space, the name of the user and press enter.

现在我们知道该用户是谁,我们可以获得有关他们的更多信息。 id命令是一个很好的起点。 输入id ,一个空格,用户名,然后按Enter键。

id dave
Output from the id command

This gives us their user ID (uid), group ID (gid) and the groups they’re a member of. A less cluttered display of the groups can be obtained by using the groups command.

这为我们提供了他们的用户ID(uid),组ID(gid)以及它们所属的组。 通过使用groups命令,可以使groups整洁。

groups dave
Output from the groups command

A nice summary is provided by the finger command. Use apt-get to install this package onto your system if you’re using Ubuntu or another Debian-based distribution. On other Linux distributions, use your Linux distribution’s package management tool instead.

finger命令提供了一个不错的摘要。 如果您使用的是Ubuntu或其他基于Debian的发行版,请使用apt-get将此软件包安装到系统上。 在其他Linux发行版上,请改用Linux发行版的程序包管理工具。

sudo apt-get install finger

Once you have finger installed, you can use it to display some information about the user in question.

安装finger ,您可以使用它来显示有关用户的一些信息。

finger dave

手指戴夫

Output from the finger command

On most Linux systems, some of these fields will be blank. The office, full name, and phone numbers are not populated by default. The “No Plan” field refers to an old scheme where you could provide a few notes for whoever was interested, about what you were working on, or planning to do. If you edit the .plan file in your home folder, the contents of that file are appended to the output from finger .

在大多数Linux系统上,其中一些字段为空白。 默认情况下,不填充办公室,全名和电话号码。 “无计划”字段是指一个旧的计划,您可以在其中为感兴趣的人,您正在从事的工作或计划要做的事情提供一些笔记。 如果您在主文件夹中编辑.plan文件,则该文件的内容将附加到finger的输出中。

To quickly reveal the name of the logged in user from the GNOME desktop used on Ubuntu and many other Linux distributions, click the system menu in the top-right corner of your screen. The bottom entry in the drop-down menu is the user name. Other Linux desktop environments should show your username in a similarly easy-to-find menu.

要从Ubuntu和许多其他Linux发行版上使用的GNOME桌面上快速显示登录用户的名称,请单击屏幕右上角的系统菜单。 下拉菜单的底部条目是用户名。 其他Linux桌面环境应在类似的易于查找的菜单中显示您的用户名。

System menu showing the user name

That was easy, just one click. But where’s the fun in that?

这很容易,只需单击一下即可。 但是那有什么乐趣呢?

You don’t get to feel like a digital detective in the same way as you do when you use the Bash shell.

使用Bash shell时,您不会像使用数字侦探一样感到自己。

翻译自: https://www.howtogeek.com/410423/how-to-determine-the-current-user-account-in-linux/

linux开通帐户

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值