[root@pattyo kickstart]# su - pattyo [pattyo@pattyo ~]$
This command will print accounts that do not have
a login shell
$ grep -v '/bin/[a-z]*sh' /etc/passwd
bin:x:1:1:bin:/bin: daemon:x:2:2:daemon:/sbin: adm:x:3:4:adm:/var/adm: lp:x:4:7:lp:/var/spool/lpd: sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail: news:x:9:13:news:/var/spool/news: uucp:x:10:14:uucp:/var/spool/uucp: operator:x:11:0:operator:/root: games:x:12:100:games:/usr/games: gopher:x:13:30:gopher:/usr/lib/gopher-data: ftp:x:14:50:FTP User:/home/ftp: nobody:x:99:99:Nobody:/: xfs:x:100:101:X Font Server:/etc/X11/fs:/bin/falseThere are other ways to do this. How about:
$ grep -v 'sh$' /etc/passwd
| bin:x:1:1:bin:/bin: | Can be used by any program |
| daemon:x:2:2:daemon:/sbin: | Used by daemons |
| adm:x:3:4:adm:/var/adm: | Used for administrative purposes |
| lp:x:4:7:lp:/var/spool/lpd: | Used by the printer control daemon |
| sync:x:5:0:sync:/sbin:/bin/sync | Used to synchronize disk updates |
| shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown | Used during system shutdown |
| halt:x:7:0:halt:/sbin:/sbin/halt | Used when the system is being halted |
| mail:x:8:12:mail:/var/spool/mail: | Used by the email server |
| news:x:9:13:news:/var/spool/news: | Used by the newsgroup server |
| uucp:x:10:14:uucp:/var/spool/uucp: | Used by programs related to the UUCP protocol |
| operator:x:11:0:operator:/root: | Can be used for system administration work, ie, backups |
| games:x:12:100:games:/usr/games: | Used by game programs to control system access |
| ftp:x:14:50:FTP User:/home/ftp: | Used for anonymous FTP access |
| nobody:x:99:99:Nobody:/: | Used as a restricted access account, ie, http account |
root:x:0:0:root:/root:/bin/bash testuser:x:2045:100:Test User:/home/testuser:/bin/bash
$ cat /etc/group root:x:0:root bin:x:1:root,bin,daemon daemon:x:2:root,bin,daemon sys:x:3:root,bin,adm adm:x:4:root,adm,daemon tty:x:5: disk:x:6:root lp:x:7:daemon,lp ... users:x:100:
Permissions on the two files:
$ ls -l /etc/passwd
-rw-r--r--
1 root root 893 Mar 12 15:54 /etc/passwd
$ ls -l /etc/shadow
-r--------
1 root root 781 Mar 12 15:54 /etc/shadow
Excerpt from /etc/shadow file using DES encryption:
testuser:N1n9MgqO7TvHk:11179:0:99999:7:::
Excerpt from /etc/shadow file using md5 encryption:
testuser:$1$adm/jjY7$F/QCYbF0.gOTMhKIY4xnT.:11901:0:99999:7:::
$ echo "some string of characters" | md5sum
$ echo "short" | md5sum
Unix password database contains hashes When user types their password, the hash function is applied and compared to the stored hashed password In theory, the password can't be recovered from the hash In practice, users pick bad passwords which are easily guessed
Highly configurable authentication scheme:
/lib/securityallows you to configure your environment for the level of security you feel you need. Loadable modules that handle the authentication tasks for all applications and services on the system. login, samba, pop, sshd ... Better than having each each service or application implement its own security policy
# cat /etc/pam.d/passwd #%PAM-1.0 auth required /lib/security/pam_pwdb.so shadow nullok account required /lib/security/pam_pwdb.so password required /lib/security/pam_cracklib.so retry=3 password required /lib/security/pam_pwdb.so use_authtok nullok md5 shadow
| module-type | control-flag | module-path | arguments |
| module-type | control-flag | module-path | arguments |
| module-type
(Management Task) |
Description |
| auth | Prompts user for identification such as a password. options: nullok, nodelay |
| account | checks account info, ensures user account and password are active |
| session | Sets up logging for application |
| password | Allows users to update password. options: nullok, md5, shadow, remember=n |
Field 2:
| Control Flag | Description |
| required | Success of the module is required, failure is not reported until all modules have executed. So user doesn't know where they failed in the process. |
| requisite | Success of the module is required, failure causes PAM to return immediate failure to the calling application. Faster but hosile users know where they failed in the auth stack |
| optional | Success or failure have no affect on the calling application |
| sufficient | If this module succeeds all the remaining modules are ignored, returns immediately to calling program. You might allow less stringent checks on your laptop then on your workstation... |
Arguments:
# less /etc/pam.d/login
auth required /lib/security/pam_securetty.so
auth required /lib/security/pam_stack.so service=system-auth
auth required /lib/security/pam_nologin.so
account required /lib/security/pam_stack.so service=system-auth
password required /lib/security/pam_stack.so service=system-auth
session required /lib/security/pam_stack.so service=system-auth
session optional /lib/security/pam_console.so
pam_nologin.so will prevent users from logging into the system if the file /etc/nologin exists. The contents of /etc/nologin is displayed during login attempt
1. Create the file /etc/nologin# echo "Sorry, no joy today" > /etc/nologin2. Type <Cntr><Alt><F2> to access a virtual console
3. Try logging in as userxx on your workstations
4. What happened?
5. Delete the /etc/nologin file and try logging in again
Excerpt from man page (man useradd):
SYNOPSIS
useradd [-c
comment] [-d home_dir]
[-e expire_date] [-f inactive_time]
[-g initial_group] [-G group[,...]]
[-m [-k skeleton_dir] | -M] [-p passwd]
[-s shell] [-u uid [ -o]] [-n] [-r] login
useradd -D
[-g default_group] [-b default_home]
[-f default_inactive] [-e default_expire_date]
[-s default_shell]
Information Returned by -D Option (returns default settings)
[root@pattyo /]# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
[root@pattyo /etc]# useradd -g users test2
[root@pattyo /etc]# tail /etc/passwd
ftp:x:14:50:FTP User:/home/ftp:
nobody:x:99:99:Nobody:/:
xfs:x:100:101:X Font Server:/etc/X11/fs:/bin/false
gdm:x:42:42::/home/gdm:/bin/bash
qcroot:x:0:0:qcroot:/home/qcroot:/bin/bash
pattyo:x:21818:111:Pattyo Test Account:/home/pattyo:/bin/tcsh
test:x:41415:100:test me:/home/test:/bin/bash
junk:x:41416:100:junk mail:/home/junk:/bin/tcsh
test3:x:41428:41428:Patty O'Reilly:/home/test3:/bin/tcsh
test2:x:41607:100::/home/test2:/bin/bash
^^^^^
# passwd pattyo Changing password for user pattyo New UNIX password: BAD PASSWORD: it does not contain enough DIFFERENT characters Retype new UNIX password:
SYNOPSIS
groupadd
[-g gid [-o]] [-r] [-f] group
Or edit the group file directly:
# vi /etc/group
SYNOPSIS
usermod [-c
comment] [-d home_dir [ -m]]
[-e expire_date] [-f inactive_time]
[-g initial_group] [-G group[,...]]
[-l login_name] [-p passwd]
[-s shell] [-u uid [ -o]] [-L|-U] login
Example 1: change the default shell for the user, test, from bash to tcsh
# grep test /etc/passwd
test:x:5001:100:Test Acct:/home/test:/bin/bash
^^^^
# usermod -s /bin/tcsh test
# grep test /etc/passwd
test:x:5001:100:Test Acct:/home/test:/bin/tcsh
^^^^
It is easy to change one's own default shell with the
chsh command.
$ chsh Changing shell for pattyo. New shell [/bin/tcsh]: /bin/bash Shell changed.Example 2: Change the primary group from test to users
total 40
drwxr-xr-x 4 root root
4096 Sep 29 16:18 .
drwxr-xr-x 37 root root
4096 Oct 3 09:44 ..
-rw-r--r-- 1 root root
24 Jul 13 1994 .bash_logout
-rw-r--r-- 1 root root
230 Aug 22 1998 .bash_profile
-rw-r--r-- 1 root root
124 Aug 23 1995 .bashrc
-rwxr-xr-x 1 root root
333 Feb 21 2000 .emacs
drwxr-xr-x 3 root root
4096 Dec 20 1998 .kde
-rw-r--r-- 1 root root
435 Sep 23 1999 .kderc
-rw-r--r-- 1 root root
3394 Mar 7 2000 .screenrc
$ alias alias cp='cp -i' alias ls='ls --color=tty' alias mv='mv -i' alias new='ls -lt|head' alias rm='rm -i'To setup a new alias from the command line for bash shell:
[root@pattyo /var]# cd /var/log
[root@pattyo log]# big
-rw-r--r-- 1 root root
5981912 Oct 2 17:16 lastlog
-rw------- 1 root root
2756092 Sep 24 03:58 secure.2
-rwx------ 1 root root
2026574 Sep 24 03:58 syslog.2
-rw------- 1 root root
1825869 Sep 29 17:09 secure.1
-rw------- 1 root root
1468097 Sep 12 03:57 secure.4
-rwx------ 1 root root
1355669 Oct 1 03:58 syslog.1
-rw------- 1 root root
818708 Sep 17 03:59 secure.3
-rw------- 1 root root
696420 Oct 1 04:02 messages.1
-rw-rw-r-- 1 root utmp
664704 Sep 29 17:04 wtmp.1
-rwx------ 1 root root
398008 Sep 17 04:01 syslog.3
*You can add your aliases to the .bashrc file in your
home directory.