As we know Linux is a multiuser system, users can be logged in at the same time on the same machine or a remote machine and user sessions can be theoretically infinite. Today we see some control necessary for user management in Linux, commands that remain unchanged for years, while the GUI change constantly making often waste time.
All of the following commands have to do with user monitoring.
Who tells us how many and which users are connected to the system (and which computer):
joe@joe-NF61S-M2A:~$ who joe tty1 2013-02-16 16:57 false pts / 1 2013-02-26 10:14 (:2) cast tty7 2013-02-24 18:11
W displays logged in users and programs running:
joe@joe-NF61S-M2A:~ $ In 10:16:56 up 9 days, 17:20, 3 users, load average: 1,00, 2,15, 2,44 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT joe tty1 16Feb13 14:59m 0.62s 0.60s-bash :2 10:14 0.00s 0.66s 0.62s gnome-terminal vale tty7 Sun18 9days 1:03m 1.15s gnome-session -
Whoami returns the user name that launched whoami:
joe@joe-NF61S-M2A:~$ whoami joe
Last shows the users who have logged in the past:
joe@joe-NF61S-M2A:~ $ Baby :2 Tue Feb 26 10:14 still logged in :2 Wed Feb 25 19:17 - 10:14 (14:56) joe pts / 5 :0 Thu Feb 21 11:46 - 18:10 (3+06:23) joe pts / 4 :0 Thu Feb 21 11:41 - 18:10 (3+06:28) joe pts / 1 :0 Thu Feb 21 11:03 - 18:10 (3+07:06) joe pts / 1 :0 Sat Feb 16 16:58 - 18:42 (01:44) joe tty1 Sat Feb 16 16:57 still logged in joe tty1 Sat Feb 16 16:57 - 16:57 (00:00) reboot system boot 3.2.0-37-generic Sat Feb 16 16:57 - 10:18 (9+17:20) joe pts / 5 :0 Thu Feb 14 11:09 - crash (2+05:48) reboot system boot 3.2.0-37-lowlate Thu Feb 14 11:08 - 10:18 (11+23:09) joe pts / 5 :0 Thu Feb 14 10:38 - 11:06 (00:27) joe pts / 3 :0 Thu Feb 14 10:24 - 11:06 (00:41) joe pts / 1 :0 Wed Feb 13 10:24 - 11:06 (1+00:42) reboot system boot 3.2.0-37-generic Tue Feb 12 11:46 - 11:07 (1+23:21) reboot system boot 3.2.0-37-generic Tue Feb 12 11:46 - 11:45 (00:00) joe pts / 4 :0 Wed Feb 4 15:44 - crash (7+20:01) joe pts / 0 :0 Wed Feb 4 15:43 - crash (7+20:02) reboot system boot 3.2.0-37-generic Mon Feb 4 15:43 - 11:45 (7+20:02) joe pts / 3 :0 Wed Feb 4 15:06 - 15:34 (00:28) joe pts / 0 :0 Sat Feb 2 19:00 - 15:34 (1+20:34) wtmp begins Sat Feb 2 19:00:48 2013
Lastb (if the file
/var/log/btmp there) shows the last failed login attempts:
joe@joe-NF61S-M2A:~$ lastb btmp begins Fri Feb 1 07:40:22 2013
Obviously differentiate users is not a process end in itself, each user is different in terms of rights, each one will have its files in the directory “/home” on which will have full access and hierarchies between users (and groups) are defined by the file
As for the practical management of users list below is a short list of useful commands.
The command “its” It started without arguments that allows the user launches it to login as the system administrator (“root”), after entering the administrator password:
joe@joe-NF61S-M2A:~$ su Password: root@joe-NF61S-M2A:/home/joe#
Launching the same command followed qualified by the a system user, It will enable us to either login as that user while maintaining even the initial user's rights. For example, if you launch from your command “joe” loggandomi as “voucher” I will have rights “joe” and “voucher” at the same time.
joe@joe-NF61S-M2A:~ $ Su vale : vale @ joe-NF61S-M2A:/home/joe$
The command “id” It allows you to verify your identity:
joe@joe-NF61S-M2A:~ $ Id (joe) gid=1000(joe) groups = 1000(joe),4(adm),24(cdrom),27(sudo),29(audio),30(dip),46(plugdev),109(lpadmin),124(sambashare),1002(jupiter)
Useradd / Adduser
These two programs are to be launched by the system (user “root”) and allow you to add a new user to the system.
root@joe-NF61S-M2A:/home / joe # adduser foo ... Adding new group 'foo' (1003) ... Adding new user 'foo' (1002) with group 'foo' ... Create the home directory '/ home / foo' ... Copy files from "/ etc / skel ' ... Enter new UNIX password: Re-enter the new password UNIX: passwd: password updated successfully : Pippo Stanza n° : 123 Phone Number Work : 131231 Home phone number : 131221 More : They foo! The information is correct? [S/n] s
The passwd command is used to reset the password to the user that launches. If launched as an administrator will replace the root password, and if launched as administrator later qualified by the one user or replace the password for that user.
root@joe-NF61S-M2A:/home / joe # passwd foo : Re-enter the new password UNIX: passwd: password updated successfully
The chfn command replaces the personal data of a user previously recorded:
root@joe-NF61S-M2A:/home / joe # foo chfn [Pippo]: Pippot Stanza n° : 321 Phone Number Work : 132131 Home phone number : 122131 More [They foo!]: Are not foo!
The usermod command modifies the user account, allows you to add a user to a group, to set a different home, to expire the account by setting a date, to disable the account… and more. Find all information on usermod in its manual page (launching “
To delete a user account and related files is used instead userdel. The command does not return output, then the following monster also part of the file / etc / passwd that continene all users.
root@joe-NF61S-M2A:/home / joe # userdel pippo :/home/joe# cat /etc/passwd | grip 1000* joe:x:1000:1000:joe,,,:/home/joe:/bin/bash vale:x:1001:1001:Valentina Redaelli,,,:/home / vale:/bin/bash
As already said the GUI change and adapt from time to time to “target” of users (to put it in business terms) and their needs. All GUI Linux under the hood have the commands described, that unlike the GUI always remain unchanged from, beginning the development of Linux. Knowing these commands is not just a small personal goal, but becomes an added value when there is only a remote connection via terminal. In that case we would have no GUI to simplify our lives, and we still have to resort to the command line.