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

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 –

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
……………………………………………………
bikram:x:1000:1000:Sunanda Ubuntu,,,:/home/bikram:/bin/bash
mysql:x:999:999::/home/mysql:/bin/sh
guest-bF03gb:x:115:125:Guest,,,:/tmp/guest-bF03gb:/bin/bash
guest-Oi8Hsz:x:116:126:Guest,,,:/tmp/guest-Oi8Hsz:/bin/bash
guest-Y2zQPI:x:117:127:Guest,,,:/tmp/guest-Y2zQPI:/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