Linux command line- list of active users, su, sudo & gksu

Linux command- Get list of users in Ubuntu (v. 12.04 LTS). Open a terminal and type this command –
$ cat /etc/passwd

Linux command- Get list of users in Ubuntu (v. 12.04 LTS). Open a terminal and type this command –
$ cat /etc/passwd

Also you can use these commands  to view the output as pagewise

$ less /etc/passwd
more /etc/passwd”

  • All fields are separated by colon (:) symbol.
  • Total 7 fields exists.
  • The first field is username,   when user logs in. 1 to 32 characters in length

Output –

bikram:x:1000:1000:Sunanda Ubuntu,,,:/home/bikram:/bin/bash

Get only the usernames by using the AWK command, type these command in terminal :
$ awk -F’:’ ‘{ print $1}’ /etc/passwd

Change user in Terminal or console:

su command

$ su : allows you to become a super user / substitute user / spoof user / set user  / switch user account. It allows a Linux user to change the current user account associated with the running terminal /console / shell.  You must know the target user’s password.  (How to set the root user’s password in Ubuntu)

$ su -
$ su - username
$ su - root
$ su - bikram

You can also run commands as Root User-

su - root -c "ls -l /root"

A good reference article is here

Sudo command

  • Configuration file name ‘/etc/sudoers’.
  • Unlike su, sudo authenticates users against their own password rather than that of the target user.
  • sudo command allows a system admin to grant authority to certain users (or groups of users) the ability to run some (or all) commands as root or another user.

gksu : GUI for su and sudo

gksu [-u <user>] [options] <command>
gksudo [-u <user>] [options] <command>

gksu -u root 'ls /root'

Learn Linux shell programming in Kolkata. or call (+91) 9163111390