Views:
3,746,055β
Votes: 2β
Tags:
command-line
user-management
Link:
π See Original Answer on Ask Ubuntu β§ π
URL:
https://askubuntu.com/q/1188600
Title:
Is there a command to list all users? Also to add, delete, modify users, in the terminal?
ID:
/2019/11/14/Is-there-a-command-to-list-all-users_-Also-to-add_-delete_-modify-users_-in-the-terminal_
Created:
November 14, 2019
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
The first answer recommends:
cut -d: -f1 /etc/passwd
But using this and counting number of users you get:
$ cut -d: -f1 /etc/passwd | wc -l
46
46 users for a laptop computer are a lot!. So use this instead:
$ cat /etc/passwd | grep -vE '(/bin/false|/sbin/nologin|/bin/sync)' | cut -d: -f1
root
rick
guest-atkb2q
guest-u4sf2i
guest-rmlbtg
guest-mz53vp
To remove guest accounts (who donβt have saved files anyway) use:
$ cat /etc/passwd | grep -vE '(/bin/false|/sbin/nologin|/bin/sync|guest-)' | cut -d: -f1
root
rick
Some sample users removed from the listing are:
systemd-timesync:x:100:102:systemd Time Synchronization,,,:/run/systemd:/bin/false
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
sync:x:4:65534:sync:/bin:/bin/sync
guest-atkb2q:x:999:999:Guest:/tmp/guest-atkb2q:/bin/bash
It turns out most of the users on a single user system are actually programs that have set themselves up as users.