Accounts (Users and Groups)
Get Info
check current user uid/gid:
$ id
Assuming my user account is ubuntu
$ whoami
ubuntu
Or check $USER
$ echo $USER
ubuntu
List the IDs (showing one uid
, one gid
and a list of groups
):
$ id ubuntu
uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu),4(adm),20(dialout),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),109(netdev),110(lxd),999(docker)
Get UID:
$ id -u
1000
Get the read-only, effective user ID
$ echo $EUID
1000
List the groups:
$ groups ubuntu
ubuntu : ubuntu adm dialout cdrom floppy sudo audio dip video plugdev netdev lxd docker
List all groups:
$ cat /etc/group
List users:
$ cat /etc/passwd
Find out the members of a group with the name developers
you would use the following command:
$ getent group developers
Manage Users and Groups
groupadd
: add a new group
$ sudo groupadd docker
usermod
: modify user, e.g. add user to group docker
$ sudo usermod -aG docker $USER