Linux get current username

How can I find out my user name?

How do I know my username? I’ve installed Ubuntu, but I don’t know my username, only my password. I can’t access my laptop and it can’t be opened.

The login screen shows possible accounts and you only have to click (or even not have to click since you were presumably the last to log in) and type your password.

@Jayharte — did any of these answers work for you? If so, please accept one as the answer. Thank you.

9 Answers 9

Open a Terminal and type whoami

This will work on every Unix/Linux System.

@rajlego If run from recovery mode, whoami would just output root . However, in recovery mode, ls /home could be used to view the names of the system’s normally configured human users. If there’s just one such user, this output is their username; and even if there are more, it should make it pretty easy to figure out the username.

Agree with @Boris. As he mentioned in the answer, he could not login, how could he launch whoami ? It’s strange to have this answer got many vote-ups.

@TungTran — Upvotes are from googlers (like me) who came here looking for the answer to the question in the title. Some of us just need a reminder of the command that prints out the current username. But, reading the actual question, this answer is pretty useless to the asker.

This will print the value of USER environment variable to the console.

To the original asker, this is as useless as the whoami command, but in all honesty, this is perfect for those «run a blah username_here » commands where username_here part can be replaced with $USER and the whole command made more universal. Thanks.

@Ali Dehghani, $USER is an environment variable that can be changed to anything. whoami actually checks which is the currently logged in user

Читайте также:  Rebooting server in linux

Most simple way to find out your username is probably to press ctr+alt+t — this opens terminal and than you will see something like:

And that answers your question.

If you installed ubuntu, then you filled in your username, does this help jog our memory?

E.g. here where yann is the user name

enter image description here

You should boot up your Ubuntu in recovery mode. Follow the steps below:

  • Switch on your computer. Wait until the BIOS has finished loading, or has almost finished. (During this time you will probably see a logo of your computer manufacturer.) Quickly press and hold the Shift key, which will bring up the GNU GRUB menu. (If you see the Ubuntu logo, you’ve missed the point where you can enter the GRUB menu.) **
  • Select the line which starts with «Advanced options«. *
  • Select the line ending with «(recovery mode)«, probably the second line, something like: Ubuntu GNU/Linux, with Linux 3.8.0-26-generic (recovery mode)
  • Press Return and your machine will begin the boot process.
  • After a few moments, your workstation should display a menu with a number of options. One of the options (you may need to scroll down to the bottom of the list) will be «Drop to root shell prompt«. Press Return with this option highlighted.

Eventually, you could use this command to list all usernames:

I suppose you will be able to recognize your username in the list.

This will work if the user hasn’t set their root password ever. However, if someone has set it already, they can always just use a live usb or any other OS to look at the home directory(hopefully unencrypted.)

Yes, if he remembers his root password, it’s even easier. Anyway, as he said, he’s installed the Ubuntu and doesn’t know his username. I suppose he didn’t set root password.

Normally when you start your computer, you don’t have to know your username to log on, because it appears automatically in a list. And if it’s the only user account, it’s the only name listed. It should look like this:

Читайте также:  Ip address linux debian

enter image description here

If there is more than one user account, click on the name you want to use. For just one user, all you have to do is type in your password.

If your login screen does not look like that, or logging in does not work, or the problem is that booting fails before you get to the login screen, please let us know, and provide as many details as possible.

Источник

How can I find out my user name ( system login username in ubuntu 20.04 )? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

enter image description here

How do i find my system login username in Ubuntu 20.04.3 LTS ?

Just type in whoami at the command line. Or if you need it in a script variable, try something like user=$(whoami) (then echo $user or whatever).

1 Answer 1

Use this solution if you didn’t encrypt your home directory.

Do you still have the installation media(LiveCD/USB) from which you installed Ubuntu? Boot from it and select Try Ubuntu.

Go to Files and then, you will see you already installed Ubuntu partition. Click on it, it will mount.

Go to /home. Here you will see a list of all users on the system that you have created.

To jog your memory, however, what is your name? Did you enter the same name while installing Ubuntu? Do you recall the name that was displayed on the login prompt where you entered your password? Ubuntu by default sets the username as your first name in lowercase.

Example; name= John Doe, automatically set username= john

Источник

Читайте также:  Linux имя файла запрещенные символы

How to get the logged in user’s real name in Unix?

I’m looking to find out the logged in user’s real (full name) to avoid having to prompt them for it in an app I’m building. I see the finger command will output a columned list of data that includes this and was wondering if it makes sense to grep through this or is there an easier way? None of the switches for finger that I’ve found output just the real name. Any thoughts would be much appreciated.

Right on Beta, that worked beautifully. Do you think that this is safe if there is more than one logged in user? Specifically does your sed magic above return all real name’s or just the first one it encounters? Thanks!

Or: finger blah | grep Name | awk -F «Name:» ‘‘ These will work fine if there are multiple users. It just pulls the one specified.

7 Answers 7

getent passwd `whoami` | cut -d : -f 5 

( getent is usually preferable to grepping /etc/passwd ).

getent passwd "$USER" | cut -d: -f5 | cut -d, -f1 

This first fetches the current user’s line from the passwd database (which might also be stored on NIS or LDAP)

In the fetched line, fields are separated by : delimiters. The GECOS entry is the 5th field, thus the first cut extracts that.

The GECOS entry itself is possibly composed of multiple items — separated by , — of which the full name is the first item. That’s what the second cut extracts. This also works if the GECOS entry is lacking the commas. In that case the whole entry is the first item.

You can also assign the result to a variable:

fullname=$( getent passwd "$USER" | cut -d: -f5 | cut -d, -f1 ) 

Or process it further directly:

echo "$( getent passwd "$USER" | cut -d: -f5 | cut -d, -f1 )'s home is $HOME." 

Источник

Оцените статью
Adblock
detector