Friday 4 November 2022

Linux User Management



To request security privileges of superuser (root):

$ sudo 


To log in and run the current shell as root use:

user@computer:~$ sudo -i
root@computer:~# whoami
root@computer:~# exit


To find info about user use id:

$ id --help
Usage: id [OPTION]... [USER]
Print user and group information for the specified USER,
or (when USER omitted) for the current user.

  -a             ignore, for compatibility with other versions
  -Z, --context  print only the security context of the process
  -g, --group    print only the effective group ID
  -G, --groups   print all group IDs
  -n, --name     print a name instead of a number, for -ugG
  -r, --real     print the real ID instead of the effective ID, with -ugG
  -u, --user     print only the effective user ID
  -z, --zero     delimit entries with NUL characters, not whitespace;
                   not permitted in default format
      --help     display this help and exit
      --version  output version information and exitftime

Without any OPTION, print some useful set of identified information.

GNU coreutils online help: <>
Full documentation at: <>
or available locally via: info '(coreutils) id invocation'

$ id

uid=1000(test_user) gid=1000(test_user) groups=1000(test_user),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),116(lpadmin),126(sambashare),999(docker)

$ id -u

$ id -g

$ id -un

$ id -gn

$ id -G
1000 3 23 26 29 45 115 125 999

$ id -Gn
test_user adm cdrom sudo dip plugdev lpadmin sambashare docker

$ echo user:group \(id\) = $(id -u):$(id -g)
user:group (id) = 1000:1000

$ echo user:group \(name\) = $(id -un):$(id -gn)
user:group (name) = bojan:bojan

To get the current user:

$ whoami

To list all users:
$ cat /etc/passwd
To list all groups:

$ groups
test_user adm cdrom sudo dip plugdev lpadmin sambashare docker

To find out to which groups belong given user:

$ groups test_user
test_user : test_user adm cdrom sudo dip plugdev lpadmin sambashare docker

.profile file 

There is one global profile file (executed when anyone logs in):


There are three user-specific bash profile files (executed when current/specific user logs in):


If ~/.profile doesn't exist, just create it.

This is the comment at the beginning of ~/.profile:

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

How to logout current user from the Terminal?

$ gnome-session-quit


$ gnome-session-quit --no-prompt

to suppress showing Logout confirmation dialog.


No comments: