Archive for the ‘Uncategorized’ Category

h1

Updating OS EZ Template Caches

August 24, 2009

#####################################

[root@vps ~]# ls /vz/template/cache
centos-5-x86.tar.gz fedora-core-9-x86.tar.gz ubuntu-8.04-x86.tar.gz
[root@vps ~]#

[root@vps ~]# vzpkg update cache centos-5-x86
Update OS template cache for centos-5-x86 template

Loading “rpm2vzrpm” plugin
Cleaning up xml metadata
16 metadata files removed

Loading “rpm2vzrpm” plugin
Making cache files for all metadata files.
This may take a while depending on the speed of this computer
Setting up repositories
base0 100% |=========================| 1.1 kB 00:00
base1 100% |=========================| 951 B 00:00
base2 100% |=========================| 951 B 00:00
base3 100% |=========================| 951 B 00:00
primary.xml.gz 100% |=========================| 878 kB 00:00
primary.xml.gz 100% |=========================| 306 kB 00:00
base1 : ################################################## 465/465
Added 296 new packages, deleted 0 old in 4.80 seconds
primary.xml.gz 100% |=========================| 1.7 kB 00:00
primary.xml.gz 100% |=========================| 1.0 kB 00:00
filelists.xml.gz 100% |=========================| 2.8 MB 00:00
filelists.xml.gz 100% |=========================| 2.2 MB 00:00
base1 : 2/465
=== == == == ==
=== == == == ==
=== == == == ==
=== == == == ==
ev.i386 0:095-14.20.el5_3 usermode.i386 0:1.88-3.el5.2 util-linux.i386 0:2.13-0.50.el5 vim-common.i386 2:7.0.109-4.el5_2.4z zlib.i386 0:1.2.3-3
Complete!
grep: /tmp/pam/*: No such file or directory
OS template centos-5-x86 cache was updated
[root@vps ~]#

[root@vps ~]# ls /vz/template/cache
centos-5-x86.tar.gz centos-5-x86.tar.gz-old fedora-core-9-x86.tar.gz fedora-core-9-x86.tar.gz-old ubuntu-8.04-x86.tar.gz
[root@vps ~]#

[root@vps ~]# vzup2date

h1

CenOS 5.3 yum installation in VPS

August 21, 2009

-bash-3.2# cd /root/
-bash-3.2# mkdir yumfiles
-bash-3.2# cd yumfiles/
-bash-3.2# ls
-bash-3.2# vi yumdload.sh

wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/elfutils-libs-0.137-3.el5.i386.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/elfutils-libelf-0.137-3.el5.i386.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/expat-1.95.8-8.2.1.i386.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/gmp-4.1.4-10.el5.i386.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/libxml2-2.6.26-2.1.2.7.i386.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/libxml2-python-2.6.26-2.1.2.7.i386.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/m2crypto-0.16-6.el5.3.i386.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/python-elementtree-1.2.6-5.i386.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/python-iniparse-0.2.3-4.el5.noarch.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/python-sqlite-1.1.7-1.2.1.i386.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/python-urlgrabber-3.1.0-5.el5.noarch.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/readline-5.1-1.1.i386.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/rpm-4.4.2.3-9.el5.i386.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/rpm-libs-4.4.2.3-9.el5.i386.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/rpm-python-4.4.2.3-9.el5.i386.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/sqlite-3.3.6-2.i386.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/yum-3.2.19-18.el5.centos.noarch.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/yum-fastestmirror-1.1.16-13.el5.centos.noarch.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/yum-metadata-parser-1.1.2-2.el5.i386.rpm
wget http://mirror.centos.org/centos-5/5.3/os/i386/CentOS/popt-1.10.2.3-9.el5.i386.rpm

rpm -Uvh rpm-4.4.2.3-9.el5.i386.rpm rpm-libs-4.4.2.3-9.el5.i386.rpm popt-1.10.2.3-9.el5.i386.rpm –force
rpm -Uvh rpm-python-4.4.2.3-9.el5.i386.rpm
rpm -Uvh m2crypto-0.16-6.el5.3.i386.rpm python-*.rpm yum*.rpm

-bash-3.2# sh yumdload.sh
-bash-3.2#

h1

Installing PECL shared extensions

July 30, 2009

[root@server ]# ls -l `which curl` `which curl-config`
lrwxrwxrwx 1 root root 21 Mar 7 10:59 /usr/bin/curl -> /opt/curlssl/bin/curl
lrwxrwxrwx 1 root root 28 Mar 7 10:55 /usr/bin/curl-config -> /opt/curlssl/bin/curl-config

[root@server ]# cd /root/ ; wget http://pecl.php.net/get/pecl_http-1.6.3.tgz
[root@server ]# tar -zxvf pecl_http-1.6.3.tgz
[root@server ]# cd pecl_http-1.6.3
[root@server ]# phpize
[root@server ]# ./configure –with-http-curl-requests=/opt/curlssl
[root@server ]# make
[root@server ]# make test
[root@server ]# make install
[root@server ]# php -i | grep “Configuration File”
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini

[root@server ]# vi /usr/local/lib/php.ini , and add

extension=http.so ( below extension_dir line in php.ini , make sure extension_dir alredy points to the folder having http.so lib )

** curl / curl-config may depend on your system setup. you can also use –prefix=/usr/local/pecl_http or anything you want)

h1

htaccess 302 ( temporary ) and 301 ( primary) redirects

August 22, 2008

There are permanent are temporary redirect methods that can be applied to .htaccess.

A permanent redirect will notify the visitor’s browser to update any bookmarks that are linked to the page that is being redirected. Temporary redirects will not update the visitor’s bookmarks.

Temporary Redirect ( 302 redirect )
########################################
RewriteEngine on

RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^/?$ “http\:\/\/www\.domain\.com” [R=302,L]

###

Permanent Redirect ( 302 redirect )

##########################################

RewriteEngine on

RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^/?$ “http\:\/\/www\.domain\.com” [R=301,L]

###

The above example will redirect domain.com to www.domain.com in browser.

.

h1

/usr/sbin/named: symbol lookup error: /usr/sbin/named: undefined symbol: dns_dispatch_hash

July 9, 2008

up2date erased bind and bind-devel rpm and/ maybe also, removed user/group named

Note:- This was an issue on cpanel server, but same solution should work on other systems. ( on non cpanel systems, use  up2date -i  , instead of /scripts/ensurerpm

Logs:-

###############

ul  9 01:18:46 server userhelper[18586]: running ‘/usr/sbin/up2date –nox -i bind bind-devel bind-libs bind-utils bzip2 crontabs expect freetype freetype-devel gcc gcc-c++ gd gd-devel gd-progs gd-utils glibc-devel gnupg libgcc libgd1 libgd1-devel libmysqlclient10-dev libxml libxml-devel libstdc++ libstdc++-devel which lsof sysstat libxml2 libxml2-devel gamin gamin-devel lynx openssh openssh-clients openssh-server openssl openssl-devel openssl-misc perl-CPAN sharutils ucd-snmp ucd-snmp-devel ucd-snmp-utils wget XFree86-devel XFree86-libs vixie-cron’ with root privileges on behalf of ‘root’
Jul  9 01:19:14 server userdel[18593]: delete user `named’
Jul  9 01:19:14 server userdel[18593]: remove group `named’
The problem is similar:  http://bugs.centos.org/print_bug_page.php?bug_id=2247

Reason:-

============

some binaries like   dig,host,cpio etc have immutable attributes

Solution:-

###########

quick solution:-

========================

[root@server var]# cp /etc/named.conf /root/
[root@server var]# cp -apfr /var/named/ /root/
[root@server var]# /scripts/ensurerpm bind-*

Full steps I used to fix

======================

[root@server var]# cp /etc/named.conf /root/
[root@server var]# cp -apfr /var/named/ /root/
[root@server var]# /scripts/ensurerpm bind-*

Fetching Obsoletes list for channel: rhel-i386-es-4…

Fetching rpm headers…
########################################

Name                                    Version        Rel
———————————————————-
bind-chroot                             9.2.4          28.0.1.el4        i386
bind-devel                              9.2.4          28.0.1.el4        i386
bind-utils                              9.2.4          28.0.1.el4        i386

Testing package set / solving RPM inter-dependencies…
########################################
bind-chroot-9.2.4-28.0.1.el ########################## Done.
bind-devel-9.2.4-28.0.1.el4 ########################## Done.
bind-utils-9.2.4-28.0.1.el4 ########################## Done.
bind-9.2.4-28.0.1.el4.i386. ########################## Done.
Preparing              ########################################### [100%]

Installing…
1:bind-utils             ########################################### [100%]
error: unpacking of archive failed on file /usr/bin/dig: cpio: rename
There was a fatal RPM install error. The message was:
There was a rpm unpack error installing the package: bind-utils-9.2.4-28.0.1.el4
Need to create rndc.conf
Creating rndc.conf
Creating /etc/rndc.key …
Adding controls clause …
[root@server var]# service named restart
Stopping named:                                            [FAILED]
Starting named: /usr/sbin/named: symbol lookup error: /usr/sbin/named: undefined symbol: dns_dispatch_hash
[FAILED]

[root@server var]# rpm -e bind-chroot
error: package bind-chroot is not installed
[root@server var]# cd /var/named/
[root@server var]# rpm -qa | grep bind
bind-libs-9.2.4-28.0.1.el4
ypbind-1.17.2-13
[root@server var]# /scripts/ensurerpm bind

Fetching Obsoletes list for channel: rhel-i386-es-4…

Fetching rpm headers…
########################################

Name                                    Version        Rel
———————————————————-
bind                                    9.2.4          28.0.1.el4        i386

Testing package set / solving RPM inter-dependencies…
########################################
bind-9.2.4-28.0.1.el4.i386. ########################## Done.
bind-utils-9.2.4-28.0.1.el4 ########################## Done.
Preparing              ########################################### [100%]

Installing…
1:bind-utils             ########################################### [100%]
error: unpacking of archive failed on file /usr/bin/dig: cpio: rename
There was a fatal RPM install error. The message was:
There was a rpm unpack error installing the package: bind-utils-9.2.4-28.0.1.el4
[root@server var]# cd
[root@server var]# lsattr /usr/bin/dig
—-i——– /usr/bin/dig
[root@server var]# cd /usr/bin/
[root@server bin]# chattr  -ai *
[root@server bin]# cd /usr/sbin/
[root@server sbin]# chattr  -ai *
[root@server sbin]# cd /bin/
[root@server bin]# chattr  -ai *
[root@server bin]# chattr  -ai *
[root@server bin]# /scripts/ensurerpm bind bind-devel

Fetching Obsoletes list for channel: rhel-i386-es-4…

Fetching rpm headers…
########################################

Name                                    Version        Rel
———————————————————-
bind                                    9.2.4          28.0.1.el4        i386
bind-devel                              9.2.4          28.0.1.el4        i386

Testing package set / solving RPM inter-dependencies…
########################################
bind-9.2.4-28.0.1.el4.i386. ########################## Done.
bind-devel-9.2.4-28.0.1.el4 ########################## Done.
bind-utils-9.2.4-28.0.1.el4 ########################## Done.
Preparing              ########################################### [100%]

Installing…
1:bind-utils             ########################################### [100%]
2:bind                   warning: /etc/logrotate.d/named created as /etc/logrotate.d/named.rpmnew
warning: /etc/rc.d/init.d/named saved as /etc/rc.d/init.d/named.rpmorig
warning: /etc/rndc.conf created as /etc/rndc.conf.rpmnew
warning: /etc/rndc.key created as /etc/rndc.key.rpmnew
warning: /etc/sysconfig/named created as /etc/sysconfig/named.rpmnew
########################################### [100%]
3:bind-devel             ########################################### [100%]
The following packages were added to your selection to satisfy dependencies:

Name                                    Version        Release
————————————————————–
bind-utils                              9.2.4          28.0.1.el4

[root@server bin]# service named restart
Stopping named:                                            [  OK  ]
Starting named:                                            [  OK  ]
[root@server bin]#

To prevent from auto-update, add “bind*” in /etc/sysconfig/rhn/up2date

[root@ns2 ~]# grep bind  /etc/sysconfig/rhn/up2date
pkgSkipList= bind*;courier*;spamassassin*;httpd*;perl;mysql*;php*;mod_ssl*;kernel*;exim*;proftpd*;pure-ftpd*;squirrelmail*;dovecot*;nsd*;
[root@ns2 ~]#

h1

Linux or UNIX disable null passwords

July 4, 2006

Q. How do I disabling logins for user with null passwords?

A. PAM (pluggable authentication modules) is used by both Unixish (Solaris/BSD/AIX/HP-UX) oses and Linux for configuring authentication related services.

A null password allows users to log onto a system without having to supply a valid password. This is a security risk to the system. In case if you are wondering how to setup null password, try command usermod as follows:

# usermod -p “” username

The PAM configuration option that enables null passwords is the nullok module argument passed to pam_unix.so PAM module. You’ll want to remove this argument from any modules of auth type for services that allow login.

Debian Linux

Debian Linux use following two files:

  • /etc/pam/common-auth: authentication settings common to all services
  • /etc/pam.d/common-password: password-related modules common to all services

Caution: before modifying below mentioned PAM config files, make the backup of files using cp command.

a) Open /etc/pam/common-auth:

# cp /etc/pam/common-auth /etc/pam/common-auth.ORI
# vi /etc/pam/common-auth

Find out line that read as follows:

password required pam_unix.so nullok obscure min=4 max=8 md5

Remove nullok from above line so that it read as follows:

password required pam_unix.so obscure min=4 max=8 md5

b) Save the file and exit to shell prompt. Open file /etc/pam.d/common-password:

# cp /etc/pam.d/common-password /etc/pam.d/common-password.ORI
# vi /etc/pam.d/common-password

Find out line that read as follows:

auth required pam_unix.so nullok_secure

Remove nullok_secure from above line so that it read as follows:

auth required pam_unix.so

Save the file and exit to shell prompt. Now no one be able to login using null password.

Red Hat / Fedora Linux

You need to modify single file /etc/pam.d/system-auth:

# cp /etc/pam.d/system-auth /etc/pam.d/system-auth.ORI
# vi /etc/pam.d/system-auth

Find out line that read as follows:

auth sufficient /lib/security/pam_unix.so likeauth nullok

Remove nullok from above line so that it read as follows:

auth sufficient /lib/security/pam_unix.so likeauth

Save the file.

h1

Quick NFS-setup

July 2, 2006


1. NFS-server

Making a NFS-server is done in two steps. Setting up the server and then starting it.


1.1 Configurating the server

The files to edit is placed in the /etc folder.
We are going to edit the exports-, hosts.deny- and the hosts.allow-file.

/etc/exports
The /etc/exports contains information on what dirrectories you share and what permitions the clients have. Use an editor to edit the file and add a line with the following format:

directory mashine1(option11, option12) machine2(option21, option22)...

The options should be “ro”(read only) or “rw”(read/write). Also add a option called “no_root_squash”.
A line could look like this:

/home 192.168.0.(ro,no_root_squash) 192.168.0.1(rw,no_root_squash)

Instead of the 192.168.0. which is a wildcard you can write: 192.168.0.0/255.255.255.0.

/etc/hosts.deny
The /etc/hosts.deny contain information on which deamons the clients are denied to access. Insert a line which sais

ALL:ALL

This makes ALL the protocols unavailable for ALL the users.

/etc/hosts.accept
The /etc/hosts.accept contain information on which deamons the clients are allowed to access. Insert the following lines:

portmap: [client-ip or name]
lockd:   [client-ip or name]
rquotad: [client-ip or name]
mountd:  [client-ip or name]
statd:   [client-ip or name]

And that should complete the server setup.


1.2 Starting the server

Newer releases should start the NFS at startup. Check if it’s already running by running “# rpcinfo -p”. This should show something like this:

program	vers	proto	port
100000	2	tcp	111	portmapper
100000	2	udp	111	portmapper
100011	1	udp	749	rquotad
100011	2	udp	749	rquotad
100005	1	udp	759	mountd
100005	1	tcp	761	mountd
100005	2	udp	764	mountd
100005	2	tcp	766	mountd
100005	3	udp	769	mountd
100005	3	tcp	771	mountd
100003	2	udp	2049	nfs
100003	3	udp	2049	nfs
300019	1	tcp	830	amd
300019	1	udp	831	amd
100024	1	udp	944	status
100024	1	tcp	946	status
100021	1	udp	1042	nlockmgr
100021	3	udp	1042	nlockmgr
100021	4	udp	1042	nlockmgr
100021	1	tcp	1629	nlockmgr
100021	3	tcp	1629	nlockmgr
100021	4	tcp	1629	nlockmgr

If not, simply run the following commands in the following order: “rpc.portmap”, “rpc.mountd”, “rpc.nfsd”, “rpc.statd”, “rpc.lockd”, “rpc.rquotad”.
Add the commands to /etc/rc.local to make them permanent.
This should start the correct deamons. Now run the “# rpcinfo -p” again and check the table.

Now export your filesystem by typing: “# exportfs -ra”, check it by runnning “# showmount -e [ip-adresse]“.




2. NFS-client

Simlply add the following line in /etc/fstab:

# device	     mountpoint	      fs-type 	  options	dump	fsckorder
[hostip]:[folder]	[folder]	nfs	rw,hard,intr	0	0
linux.uib.no:/home/	/home/linux/	nfs	rw,hard,intr	0	0

The upper line is just a desctiption and does not need to be added, though it’s smart to add it to the top of the table.
Write “# mount -a” to remount all the lines in fstab. Now see if you can access the mount point. You should be able to access it at this point. For permanent mounting… Edit the /etc/rc.local. Add the following line:

mount -a

This run the commando mount -a at the end of your boot sequence.

Now your nfs should work!
For troubleshooting, FAQs and more detailed descripitons read the NFS-HOWTO here.
And remember to check your firewall!

h1

Linux Configuration In Office Environment

July 2, 2006

This is the collection of Linux-related tips and tricks, mostly administration and configuration that helps to integrate Linux system into Windows office environment.


Contents


To check Hard Drive speed

# /sbin/hdparm -Tt /dev/hdx /dev/hdy 
                 

where ‘x’ and ‘y’ (etc.) are the drive letters you wish to test. It will give you a transfer rate readout.


Command execution at graphical startup

From the mailing list:

I had a little trouble with this myself. I tracked down the (problem??) to /etc/X11/xdm/Xsession. ~/.xsession is supposed to be executed upon startup of X from xdm (or kdm), but it is not unless to choose default. The default option falls through the case statement and then executes ~/.xsession. So just copy /etc/X11/xdm/Xsession to ~/.xsession and edit as necessary, then choose default from the KDM login screen or edit ~/.wmrc and replace text with default. Here is a copy of mine:

#!/bin/sh
# $XConsortium: xinitrc.cpp,v 1.4 91/08/22 11:41:34 rws Exp $
 
userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/usr/X11R6/lib/X11/xinit/.Xresources
sysmodmap=/usr/X11R6/lib/X11/xinit/.Xmodmap
 
# merge in defaults and keymaps
 
if [ -f $sysresources ]; then
    xrdb -merge $sysresources
fi
 
if [ -f $sysmodmap ]; then
    xmodmap $sysmodmap
fi
 
# User defined key mapping
xmodmap -e "keycode 22 = BackSpace"
 
# GOLD key
xmodmap -e "keycode 77 = KP_F1"
 
if [ -f $userresources ]; then
    xrdb -merge $userresources
fi
 
if [ -f $usermodmap ]; then
    xmodmap $usermodmap
fi
 
# Let everybody have access
xhost+
 
# start some nice programs
#fvwm
#fvwm2
#enlightenment
exec startkde
                 


Default Runlevel

Default runlevel is set in /etc/inittab

# default runlevel
 
id:2:initdefault:
                 

Meaning of the numbers:

  • 0 –> system halt
  • 1 –> single user mode
  • 2 –> multiuser, without NFS
  • 3 –> full multiuser mode
  • 4 –> unused
  • 5 –> X11
  • 6 –> reboot


Setting up remote logins

Run GNOME Menu Editor and for each category (epoch3 | skynet | other) add an entry to the App in the GNOME Foot:

rxvt -tn xterm -cr red -fn 10x20 -sr -sl 200 -title "epoch3@tpepc20" -e rlogin -l epoch3 tpepc20
                 

Where options are:

  • -tn xterm – set TERM variable to xterm
  • -cr red – set cursor color “red”
  • -sr – set scrollbar to the right side of the terminal
  • -sl 200 – set scrollbar history to 200 lines


Hostname/IP address Resolution with WINS

In /etc/samba/smb.conf file, set:

[global]
   name resolve order = wins lmhosts bcast host
   wins server = 172.16.1.1
   wins proxy = yes
                 

Start your Linuxconf and set your eth0 to use DHCP service. Also make sure samba services are started by bootup procedure. Restart you machine and you should be getting dynamically assigned IP address and your hostname should be resolved by DNS/WINS correctly.


Printing to Windows Print Queue

1. First, SAMBA should be properly configured. In /etc/samba/smb.conf file, set:

[global]
        workgroup = INTEGRAL
        netbios name = vgrinche-nt
        server string = Samba Server
        security = user
        password server = *
        log level = 1
        os level = 1
        dns proxy = No
        encrypt passwords = yes
        smb passwd file = /etc/samba/smbpasswd
        username map = /etc/samba/smbusers
 
[homes]
        comment = Home Directories
        browseable = no
        writable = yes
        read only = no
 
[printers]
        comment = All Printers
        security = Server
        path = /var/spool/samba
        browseable = No
        guest ok = no
        printable = Yes
        public = Yes
        create mode = 0700
                 

2. Create a user named vgrinche with linuxconf tool.

3. Create SAMBA password file:

# smbpasswd -a vgrinche
                 

4. Install enscript from RH CD-ROM.

5. Login as root (# su - )

6. Run RH printtool utility and set:

  • Queue Name: lp
  • Queue Type: Windows Printer SMB
  • Share: //EUCLID/HP8150upstrs
  • User: vgrinche
  • Workgroup: INTEGRAL
  • Printer Driver: HP LaserJet 8150 (postscript driver)
  • Save and restart daemon

7. Create mount points:

# mkdir /mnt/pascal
# mkdir /mnt/pascal/Epoch
# mkdir /mnt/pascal/V2V3
                 

8. Add mount points to /etc/fstab

//pascal/Epoch/ /mnt/pascal/Epoch  smbfs  username=vgrinche,noauto,ro,user 0 0
//pascal/V2V3/  /mnt/pascal/V2V3   smbfs  username=vgrinche,noauto,ro,user 0 0
                 

Optionally, you can specify password after username as password=PASSWORD

If you don’t know the printer’s name, or it has been changed, you can always find it out with LinNeighborhood. Browse EUCLID share – all the printers are listed there.


Mounting Windows Shares

The two commands mount -t smbfs and smbmount are essentially equivalent with slight but subtle differences. If you use one command to mount a share, you have to use the same command to unmount the share.

Their syntax is almost identical:

smbmount //server/share /mountpoint [-o options]
 
mount -t smbfs //server/share /mountpoint [-o options]
                 

If you use smbmount, the user who issues the smbmount command must own the mount point. This is true even if you create an /etc/fstab entry to allow users to mount shares. smbmount works better if you want allow individual users to mount remote shares.

Avaliable options:

  • username=name     This option specifies the username to be used on the server. smbmount sends this name to the Windows server in order to gain access to files. If UNIX username is different from the Windows username, this is the option to use. You can specify user name, password, and Windows workgroup: -o username=VGRINCHE/INTEG%MYSECRET
  • password=passwd     If you don’t include this option with smbmount, the program prompts you for the password.
  • netbiosname=name     This option sets the name by which the client goes when it connects to the server. It defaults to your system’s host name.
  • uid=id     This option sets the apparent owner of the files on the local mounted filesystem. It can be either user name or a number.
  • gid=id      This option sets the apparent group ownership of the mounted files.
  • fmask=mask      This option sets the permissions used for remote files on the share once it is mounted. Typically, it is fmask=640.
  • dmask=mask      Same as above, but for directories.

By default, many Samba installations give the smbmnt program (helper program for smbmount) superuser privileges for execution only. If ordinary user must be able to use these programs, it must be set user ID (suid) root:

$ chmod a+s /usr/bin/smbmnt /usr/bin/smbumount
                 

EXAMPLE:

// Mount 
 
smbmount //HILBERT/goes /export/home/vlad/Documents/GOES_RPM \
  -o username=VGRINCHE,password=MY_SECRET,uid=vlad,gid=epoch,fmask=666,dmask=777
 
// Unmount
 
smbumount /export/home/vlad/Documents/GOES_RPM
                 


Configuring Time Feed

Time feed is taken from outside (internet) sources.

  1. Download xntp3.*.rpm package
  2. Edit /etc/ntp.conf configuration file, and add following lines to it:
server          tick.usno.navy.mil      prefer
server          tock.usno.navy.mil      prefer
server          time.nist.gov           prefer
                         
  1. Restart xntpd server.

Time will slowly drift and synchronize with the outside servers.


Configuring FTP daemon

By default, wu-ftpd package is not installed. Also, make sure that ksh is listed in /etc/shells file.


Configuring rlogin

To allow logins from one account (vlad) to another (epoch3) on the same machine, change your ~/.rhosts file to look like:

vgrinche-nt vlad
                 

Change permissions of ~/.rhosts to 0400.

By default, ~/.rhosts file is ignored. To enable it, change PAM policy by commenting out line below in the file /etc/pam.d/rlogin

# auth       required    /lib/security/pam_securetty.so
                 

Now, try % rlogin vgrinche-nt -l epoch3 and it should not ask for password.


Booting into damaged root filesystem

If LILO’s MBR record or any part of your /boot directory is damaged and you can not login into your system anymore, last thing to try is booting with distirbution disk and telling it to mount your root partition as root (/). Pop in your RH cd-rom and type in at Linux: prompt

linux single root=/dev/hda1 initrd=
                 

To repair the installation, boot CD with

linux resque
                 

If the boot message scrolled too fast off the screen, and you haven’t had a chance to see the error report, use Shift-Up/Down to scroll up/down the screen.

This is the way to remount various filesystems if you find yourself in “repair” mode and want to change some files:

 
mount proc /proc -t proc
mount /dev/hda2 / -o remounte,rw
mount /dev/hda1 /boot
                 


Mounting /proc failed

Once in a blue moon I get this error message. Some people reported it happening after an upgrade.

 
Mounting proc filesystem dup2: Bad file descriptor
No such partition found ...
                 

Somehow the effect of the update modifed /dev/null to be a regular file with some sort of message in it … hence “Bad file descriptor“. To fix, login into repair mode, remount root filesystem as read-write, and restore /dev/null:

 
# mount -n -o remount,rw /
# rm -f /dev/null
# mknod -m 0666 /dev/null c 1 3
                 


Downloading RedHat ISO distribution files

Downloads are slow and I might do them in pieces. Therefore, I use wget from GNU. Here is the rough script that does the job. I admit it is not perfect, but is sufficient for now:

wget --glob=on --tries=0  \
   ftp://anonymous:vgrinche%40integ.com@distro.ibiblio.org
          //pub/linux/distributions/redhat/7.2/en/iso/i386/enigma-i386-disc?.iso
 
wget --glob=on --tries=0  \
   ftp://anonymous:vgrinche%40integ.com@distro.ibiblio.org
         //pub/linux/distributions/redhat/7.2/en/iso/i386/enigma-SRPMS-disc?.iso
                 


Making and using ext2 floppy

First, you format ext2 floppy with:

# su 
# /sbin/fdformat /dev/fd0H1440
# /sbin/mkfs -t ext2 -m 0 /dev/fd0H1440 1440
                 

Then, modify you /etc/fstab floppy entry. This would allow anyone to mount and modify floppy disk.

/dev/fd0 /mnt/floppy auto noauto,users,nosuid,nodev,rw,sync,noexec 0 0
                 

And finally, mount your floppy as user, and then change /mnt/floppy permissions to 0777. Otherwise, /sbin/mount would set directory’s permissions to 0755 even if nosuid is specified! /sbin/mount is setuid binary.

# chmod 0777 /mnt/floppy
                 


I have no “core” and I must debug

The ulimit controls the size limit of serveral things in your Linux system, among them, the size of the core file. Issuing a ulimit -c 0 will tell Linux to disable core files. It is set in /etc/profile.

Another possible place for that limit being reinforced is in file /etc/security/limits.com It is a part of PAM system. The “soft” and “hard” refers to the kind of limits imposed.


Apache Web Server Setup

Edit the Apache configuration file, /etc/httpd/conf/httpd.conf and add following lines:

<IfModule mod_userdir.c>
    #
    # To enable requests to /~user/ to serve the user's public_html
    # directory, use this directive instead of "UserDir disable":
    #
    UserDir public_html
 
</IfModule>
                 

 

<Directory "/export/home/vlad/public_html">
        AllowOverride FileInfo AuthConfig Limit
        Options MultiViews Indexes IncludesNoExec FollowSymLinks
        <Limit GET POST OPTIONS PROPFIND>
                Order allow,deny
                Allow from all
        </Limit>
        <Limit PUT DELETE PATCH PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
                Order deny,allow
                Deny from all
        </Limit>
</Directory>
                 

 

<Files /export/home/vlad/public_html/SelfEmployment/index.html>
        Order allow,deny
        Deny from all
</Files>
                 

Then, restart you web server.


Creating GNOME2 Custom Menus

To create a custom menu, first add a directory entry, Logins.directory to ~/.gnome2/vfolders directory. The file should look something like this:

[Desktop Entry]
Name=Logins
Comment=Logins menu
Icon=gnome-util.png
Type=Directory
                 

Each item in the Logins menu is described by .desktop file. For example, a remote login to rpm@rpmdev1 account is described by ~/.gnome2/vfolders/Logins/rpm_rpmdev1.desktop, which looks like this:

[Desktop Entry]
Name=rpm@rpmdev1
Comment=
Exec=rxvt -ls -bg black -fg white -tn xterm -cr red -fn 10x20 -sr -sl 200 -title
         "rpm@rpmdev1" -e rlogin -l rpm rpmdev1
Icon=gnome-terminal.png
Type=Application
X-GNOME-DocPath=gnome-terminal/index.html
Categories=Logins;Utility
Encoding=UTF-8
X-Desktop-File-Install-Version=0.3
OnlyShowIn=GNOME;
 
                 

Notice the Categories entry. It is set to Logins;Utility. There is a dependency between that and the fact that there is Logins.directory file. This dependency is established by ~/.gnome2/vfolders/applications.vfolder-info file which is a modified copy of the system-wide file by the same name. The modifications add describe a new menu entry, Logins, and add a directory where *.desktop files for that entry can be found, ~/.gnome2/vfolders/Logins.

Here are the relevent modifications:

<VFoldersInfo>
   <MergeDir>/export/home/vlad/.gnome2/vfolders/Logins</MergeDir>
</VFoldersInfo>
 
<!-- Logins -->
<Folder>
   <Name>Logins</Name>
   <Desktop>Logins.directory</Desktop>
   <Query>
     <And>
       <Keyword>Logins</Keyword>
       <Keyword>Utility</Keyword>
       <Not>
          <Keyword>System</Keyword>
       </Not>
     </And>
   </Query>
   <DontShowIfEmpty/>
</Folder>
                 

System-wide files:

  1. /etc/gnome-vfs-2.0/vfolders/applications.folder-info
  2. /usr/share/gnome/vfolder/*.directory
  3. /usr/share/applications/*.desktop

Useful Links:

  1. Gnome2 Release Notes
  2. Menu Editing Guide
  3. Desktop Entry Standard


Switching Between Window Managers

To switch between WMs, bring up Desktop Preferences->Advanced->Sessions window, find your running WM and change its status from respawn to normal. Then kill it, start another WM and save the session:

 
killall sawfish && sleep 5 && metacity && gnome-session-save &&
                 

 


Make bigger fonts in Evolution

To change the font size used in menus and other app text for non-Gnome apps, edit /etc/X11/fs/config:

 
// file: /etc/X11/fs/config
 
// 1. Swhitch order of these 2 lines:
 
/usr/X11R6/lib/X11/fonts/75dpi:unscaled,
/usr/X11R6/lib/X11/fonts/100dpi:unscaled,
 
// 2. Change the line:
 
    default-resolutions = 75,75,100,100
To:
 
    default-resolutions = 100,100,75,75
 
                 

h1

Search & Replace – sed

June 16, 2006

You can use the sed command to change all occurrences of one string to another within a file, just like the search-and-replace feature of your word processor. The sed command can also delete a range of lines from a file. Since sed is a stream editor, it takes the file given as input, and sends the output to the screen, unless you redirect output to a file. In other words, sed does not change the input file.

The general forms of the sed command are as follows:

Substitution sed 's/<oldstring>/<newstri ng>/g' <file>
Deletion sed '<start>,<end>d' < file>

Let's start with a substitution example. If you want to change all occurrences of lamb to ham in the poem.txt file in the grep example, enter this:

sed 's/lamb/ham/g' poem.txt
Mary had a little ham
Mary fried a lot of spam
Jack ate a Spam sandwich
Jill had a ham spamwich

In the quoted string, the "s" means substitute, and the "g" means make a global change. You can also leave off the "g" (to change only the first occurrence on each line) or specify a number instead (to change the first n occurrences on each line).

Now let's try an example involving deletion of lines. The values for start and end can be either a line number or a pattern to match. All lines from the start line to the end line are removed from the output. This example will delete starting at line 2, up to and including line 3:

sed '2,3d' poem.txt
Mary had a little lamb
Jill had a lamb spamwich

This example will delete starting at line 1, up to and including the next line containing Jack:

sed '1,/Jack/d' poem.txt
Jill had a lamb spamwich

The most common use of sed is to change one string of text to another string of text. But I should mention that the strings that sed uses for search and delete are actually regular expressions. This means you can use pattern matching, just as with grep. Although you'll probably never need to do anything like this, here's an example anyway. To change any occurrences of lamb at the end of a line to ham, and save the results in a new file, enter this:

sed 's/lamb$/ham/g' poem.txt > new.file

Since we directed output to a file, sed didn't print anything on the screen. If you look at the contents of new.file it will show these lines:

Mary had a little ham
Mary fried a lot of spam
Jack ate a Spam sandwich
Jill had a lamb spamwich

Use the man sed command for more information on using sed.

h1

Linux and password

June 10, 2006

Why shadow your passwd file?

On a Linux system without the Shadow Suite installed, user information including passwords is stored in the /etc/passwd file. Many people would say that the password is stored in an encrypted format. If you ask a cryptography expert, however, he or she will tell you that the password is actually in an encoded rather than encrypted format because when using crypt(3), the text is set to null and the password is the key. Therefore, from here on, I will use the term encoded in this document.

The algorithm used to encode the password field is technically referred to as a one way hash function. This is an algorithm that is easy to compute in one direction, but very difficult to calculate in the reverse direction. More about the actual algorithm used can be found in section 2.4 or your crypt(3) manual page.

When a user picks or is assigned a password, it is encoded with a randomly generated value called the salt. This means that any particular password could be stored in 4096 different ways. The salt value is then stored with the encoded password.

When a user logs in and supplies a password, the salt is first retrieved from the stored encoded password. Then the supplied password is encoded with the salt value, and then compared with the encoded password. If there is a match, then the user is authenticated.

It is computationally difficult (but not impossible) to take a randomly encoded password and recover the original password. However, on any system with more than just a few users, at least some of the passwords will be common words (or simple variations of common words).

System crackers know all this, and will simply encrypt a dictionary of words and common passwords using all possible 4096 salt values. Then they will compare the encoded passwords in your /etc/passwd file with their database. Once they have found a match, they have the password for another account. This is referred to as a dictionary attack, and is one of the most common methods for gaining or expanding unauthorized access to a system.

If you think about it, an 8 character password encodes to 4096 * 13 character strings. So a dictionary of say 400,000 common words, names, passwords, and simple variations would easily fit on a 4GB hard drive. The attacker need only sort them, and then check for matches. Since a 4GB hard drive can be had for under $1000.00, this is well within the means of most system crackers.

Also, if a cracker obtains your /etc/passwd file first, they only need to encode the dictionary with the salt values actually contained in your /etc/passwd file. This method is usable by your average teenager with a couple of hundred spare Megabytes and a 486 class computer.

Even without lots of drive space, utilities like crack(1) can usually break at least a couple of passwords on a system with enough users (assuming the users of the system are allowed to pick their own passwords).

The /etc/passwd file also contains information like user ID's and group ID's that are used by many system programs. Therefore, the /etc/passwd file must remain world readable. If you were to change the /etc/passwd file so that nobody can read it, the first thing that you would notice is that the ls -l command now displays user ID's instead of names!

The Shadow Suite solves the problem by relocating the passwords to another file (usually /etc/shadow). The /etc/shadow file is set so that it cannot be read by just anyone. Only root will be able to read and write to the /etc/shadow file. Some programs (like xlock) don't need to be able to change passwords, they only need to be able to verify them. These programs can either be run suid root or you can set up a group shadow that is allowed read only access to the /etc/shadow file. Then the program can be run sgid shadow.

By moving the passwords to the /etc/shadow file, we are effectively keeping the attacker from having access to the encoded passwords with which to perform a dictionary attack.

Additionally, the Shadow Suite adds lots of other nice features:

  • A configuration file to set login defaults (/etc/login.defs)
  • Utilities for adding, modifying, and deleting user accounts and groups
  • Password aging and expiration
  • Account expiration and locking
  • Shadowed group passwords (optional)
  • Double length passwords (16 character passwords) NOT RECOMMENDED
  • Better control over user's password selection
  • Dial-up passwords
  • Secondary authentication programs
  • Pluggable Authentication Modules (PAM) support
  • Support for setting ulimits

Installing the Shadow Suite contributes toward a more secure system, but there are many other things that can also be done to improve the security of a Linux system. For more Linux security issues and tips, see the Linux Security HOWTO.

For current information on other Linux security issues, including warnings on known vulnerabilities see the Linux Security WWW. and the Linux Security home page.

Why you might NOT want to install the Shadow Suite.

There are a few circumstances and configurations in which installing the Shadow Suite would NOT be a good idea:

  • Your distribution already contains shadow code. You should look in your /etc/passwd file and determine if passwords are actually being stored there. If you don't see any, try changing your password and look again. Many distributions come with accounts with no password.
  • If you are running RedHat, you should use the RPM that is approporiate for your RedHat version to install shadow support. RedHat's shadow support is not the same as that documented here, so refer to RedHat's documentation
  • If the machine does not contain any user accounts, then you probably don't need shadow support, unless you are installing it just to gain the experience.
  • If your machine is running on a LAN and is using NIS (Network Information Services) to get or supply user names and passwords to other machines on the network you would an NIS compatable shadow suite.. (This can actually be done, but is beyond the scope of this document, and should be done in conjunction with cryptographically secure software)
  • If your machine is being used by terminal servers to verify users via NFS (Network File System), NIS, or some other method you probably can't shadow your system without breaking that software. If your terminal server supports RADIUS, that is probably your best solution.
  • If your machine runs other software that validates users, and there is no shadow version available, and you don't have the source code you shouldn't install the Shadow Suite.
  • If your machine is setup as a RADIUS server that authenticates users that are connecting to a terminal server. You actually can and should shadow a RADIUS server, but you will need a RADUIS server that has been patched to allow shadowed passwords. Both Livingston and Ascend have shadow support in their Radius servers. Some RADIUS servers have shadow support, but don't recognize the expired account and expired password fields.

Format of the /etc/passwd file

A non-shadowed /etc/passwd file has the following format:

username:passwd:UID:GID:full_name:directory:shell

Where:

username

The user (login) name

passwd

The encoded password

UID

Numerical user ID

GID

Numerical default group ID

full_name

The user's full name – Actually this field is called the GECOS (General Electric Comprehensive Operating System) field and can store information other than just the full name. The Shadow commands and manual pages refer to this field as the comment field.

directory

User's home directory (Full pathname)

shell

User's login shell (Full Pathname)

For example:

username:Npge08pfz4wuk:503:100:Full Name:/home/username:/bin/sh

Where Np is the salt and ge08pfz4wuk is the encoded password. The encoded salt/password could just as easily have been kbeMVnZM0oL7I and the two are exactly the same password. There are 4096 possible encodings for the same password. (The example password in this case is 'password', a really bad password).

Once the shadow suite is installed, the /etc/passwd file would instead contain:

username:x:503:100:Full Name:/home/username:/bin/sh

The x in the second field in this case is now just a place holder. The format of the /etc/passwd file really didn't change, it just no longer contains the encoded password. This means that any program that reads the /etc/passwd file but does not actually need to verify passwords will still operate correctly.

The passwords are now relocated to the shadow file (usually /etc/shadow file).

Format of the shadow file

The /etc/shadow file contains the following information:

username:passwd:last:may:must:warn:expire:disable:reserved

Where:

username

The User Name

passwd

The Encoded password

last

Days since Jan 1, 1970 that password was last changed

may

Days before password may be changed

must

Days after which password must be changed

warn

Days before password is to expire that user is warned

expire

Days after password expires that account is disabled

disable

Days since Jan 1, 1970 that account is disabled

reserved

A reserved field

The previous example might then be:

username:Npge08pfz4wuk:9479:0:10000::::

Review of crypt(3).

From the crypt(3) manual page:

"crypt is the password encryption function. It is based on the Data Encryption Standard algorithm with variations intended (among other things) to discourage use of hardware implementations of a key search.

The key is a user's typed password. The encoded string is all NULLs

The salt is a two-character string chosen from the set a-zA-Z0-9./. This string is used to perturb the algorithm in one of 4096 different ways.

By taking the lowest 7 bits of each character of the key, a 56-bit key is obtained. This 56-bit key is used to encrypt repeatedly a constant string (usually a string consisting of all zeros). The returned value points to the encrypted password, a series of 13 printable ASCII characters (the first two characters represent the salt itself). The return value points to static data whose content is overwritten by each call.

Warning: The key space consists of 2**56 equal 7.2e16 possible values. Exhaustive searches of this key space are possible using massively parallel computers. Software, such as crack(1), is available which will search the portion of this key space that is generally used by humans for passwords. Hence, password selection should, at minimum, avoid common words and names. The use of a passwd(1) program that checks for crackable passwords during the selection process is recommended.

The DES algorithm itself has a few quirks which make the use of the crypt(3) interface a very poor choice for anything other than password authentication. If you are planning on using the crypt(3) interface for a cryptography project, don't do it: get a good book on encryption and one of the widely available DES libraries."

Most Shadow Suites contain code for doubling the length of the password to 16 characters. Experts in des recommend against this, as the encoding is simply applied first to the left half and then to the right half of the longer password. Because of the way crypt works, this may make for a less secure encoded password then if double length passwords were not used in the first place. Additionally, it is less likely that a user will be able to remember a 16 character password.

There is development work under way that would allow the authentication algorithm to be replaced with something more secure and with support for longer passwords (specifically the MD5 algorithm) and retain compatibility with the crypt method.

If you are looking for a good book on encryption, I recommend:

        "Applied Cryptography: Protocols, Algorithms, and Source Code in C"
        by Bruce Schneier <schneier@chinet.com>
        ISBN: 0-471-59756-2

 

 

 

Putting the Shadow Suite to use.

This section discusses some of the things that you will want to know now that you have the Shadow Suite installed on your system. More information is contained in the manual pages for each command.

Adding, Modifying, and deleting users

The Shadow Suite added the following command line oriented commands for adding, modifying, and deleting users. You may also have installed the adduser program.

useradd

The useradd command can be used to add users to the system. You also invoke this command to change the default settings.

The first thing that you should do is to examine the default settings and make changes specific to your system:

useradd -D


GROUP=1
HOME=/home
INACTIVE=0
EXPIRE=0
SHELL=
SKEL=/etc/skel


The defaults are probably not what you want, so if you started adding users now you would have to specify all the information for each user. However, we can and should change the default values.

On my system:

  • I want the default group to be 100
  • I want passwords to expire every 60 days
  • I don't want to lock an account because the password is expired
  • I want to default shell to be /bin/bash

To make these changes I would use:

useradd -D -g100 -e60 -f0 -s/bin/bash

Now running useradd -D will give:


GROUP=100
HOME=/home
INACTIVE=0
EXPIRE=60
SHELL=/bin/bash
SKEL=/etc/skel


Just in case you wanted to know, these defaults are stored in the file /etc/default/useradd.

Now you can use useradd to add users to the system. For example, to add the user fred, using the defaults, you would use the following:

useradd -m -c "Fred Flintstone" fred

This will create the following entry in the /etc/passwd file:

fred:*:505:100:Fred Flintstone:/home/fred:/bin/bash

And the following entry in the /etc/shadow file:

fred:!:0:0:60:0:0:0:0

fred's home directory will be created and the contents of /etc/skel will be copied there because of the -m switch.

Also, since we did not specify a UID, the next available one was used.

fred's account is created, but fred still won't be able to login until we unlock the account. We do this by changing the password.

passwd fred


Changing password for fred
Enter the new password (minimum of 5 characters)
Please use a combination of upper and lower case letters and numbers.
New Password: *******
Re-enter new password: *******


Now the /etc/shadow will contain:

fred:J0C.WDR1amIt6:9559:0:60:0:0:0:0

And fred will now be able to login and use the system. The nice thing about useradd and the other programs that come with the Shadow Suite is that they make changes to the /etc/passwd and /etc/shadow files atomically. So if you are adding a user, and another user is changing their password at the same time, both operations will be performed correctly.

You should use the supplied commands rather than directly editing /etc/passwd and /etc/shadow. If you were editing the /etc/shadow file, and a user were to change his password while you are editing, and then you were to save the file you were editing, the user's password change would be lost.

Here is a small interactive script that adds users using useradd and passwd:


#!/bin/bash
#
# /sbin/newuser - A script to add users to the system using the Shadow
#                 Suite's useradd and passwd commands.
#
# Written my Mike Jackson <mhjack@tscnet.com> as an example for the Linux
# Shadow Password Howto.  Permission to use and modify is expressly granted.
#
# This could be modified to show the defaults and allow modification similar
# to the Slackware Adduser program.  It could also be modified to disallow
# stupid entries.  (i.e. better error checking).
#
##
#  Defaults for the useradd command
##
GROUP=100        # Default Group
HOME=/home       # Home directory location (/home/username)
SKEL=/etc/skel   # Skeleton Directory
INACTIVE=0       # Days after password expires to disable account (0=never)
EXPIRE=60        # Days that a passwords lasts
SHELL=/bin/bash  # Default Shell (full path)
##
#  Defaults for the passwd command
##
PASSMIN=0        # Days between password changes
PASSWARN=14      # Days before password expires that a warning is given
##
#  Ensure that root is running the script.
##
WHOAMI=`/usr/bin/whoami`
if [ $WHOAMI != "root" ]; then
        echo "You must be root to add news users!"
        exit 1
fi
##
#  Ask for username and fullname.
##
echo ""
echo -n "Username: "
read USERNAME
echo -n "Full name: "
read FULLNAME
#
echo "Adding user: $USERNAME."
#
# Note that the "" around $FULLNAME is required because this field is
# almost always going to contain at least on space, and without the "'s
# the useradd command would think that you we moving on to the next
# parameter when it reached the SPACE character.
#
/usr/sbin/useradd -c"$FULLNAME" -d$HOME/$USERNAME -e$EXPIRE \
        -f$INACTIVE -g$GROUP -m -k$SKEL -s$SHELL $USERNAME
##
#  Set password defaults
##
/bin/passwd -n $PASSMIN -w $PASSWARN $USERNAME >/dev/null 2>&1
##
#  Let the passwd command actually ask for password (twice)
##
/bin/passwd $USERNAME
##
#  Show what was done.
##
echo ""
echo "Entry from /etc/passwd:"
echo -n "   "
grep "$USERNAME:" /etc/passwd
echo "Entry from /etc/shadow:"
echo -n "   "
grep "$USERNAME:" /etc/shadow
echo "Summary output of the passwd command:"
echo -n "   "
passwd -S $USERNAME
echo ""


Using a script to add new users is really much more preferable than editing the /etc/passwd or /etc/shadow files directly or using a program like the Slackware adduser program. Feel free to use and modify this script for your particular system.

For more information on the useradd see the online manual page.

usermod

The usermod program is used to modify the information on a user. The switches are similar to the useradd program.

Let's say that you want to change fred's shell, you would do the following:

usermod -s /bin/tcsh fred

Now fred's /etc/passwd file entry would be change to this:

fred:*:505:100:Fred Flintstone:/home/fred:/bin/tcsh

Let's make fred's account expire on 09/15/97:

usermod -e 09/15/97 fred

Now fred's entry in /etc/shadow becomes:

fred:J0C.WDR1amIt6:9559:0:60:0:0:10119:0

For more information on the usermod command see the online manual page.

userdel

userdel does just what you would expect, it deletes the user's account. You simply use:

userdel -r username

The -r causes all files in the user's home directory to be removed along with the home directory itself. Files located in other file system will have to be searched for and deleted manually.

If you want to simply lock the account rather than delete it, use the passwd command instead.

The passwd command and passwd aging.

The passwd command has the obvious use of changing passwords. Additionally, it is used by the root user to:

  • Lock and unlock accounts (-l and -u)
  • Set the maximum number of days that a password remains valid (-x)
  • Set the minimum days between password changes (-n)
  • Sets the number of days of warning that a password is about to expire (-w)
  • Sets the number of days after the password expires before the account is locked (-i)
  • Allow viewing of account information in a clearer format (-S)

For example, let look again at fred

passwd -S fred
fred P 03/04/96 0 60 0 0

This means that fred's password is valid, it was last changed on 03/04/96, it can be changed at any time, it expires after 60 days, fred will not be warned, and and the account won't be disabled when the password expires.

This simply means that if fred logs in after the password expires, he will be prompted for a new password at login.

If we decide that we want to warn fred 14 days before his password expires and make his account inactive 14 days after he lets it expire, we would need to do the following:

passwd -w14 -i14 fred

Now fred is changed to:

fred P 03/04/96 0 60 14 14

For more information on the passwd command see the online manual page.

The login.defs file.

The file /etc/login is the configuration file for the login program and also for the Shadow Suite as a whole.

/etc/login contains settings from what the prompts will look like to what the default expiration will be when a user changes his password.

The /etc/login.defs file is quite well documented just by the comments that are contained within it. However, there are a few things to note:

  • It contains flags that can be turned on or off that determine the amount of logging that takes place.
  • It contains pointers to other configuration files.
  • It contains defaults assignments for things like password aging.

From the above list you can see that this is a rather important file, and you should make sure that it is present, and that the settings are what you desire for your system.

Group passwords.

The /etc/groups file may contain passwords that permit a user to become a member of a particular group. This function is enabled if you define the constant SHADOWGRP in the /usr/src/shadow-YYMMDD/config.h file.

If you define this constant and then compile, you must create an /etc/gshadow file to hold the group passwords and the group administrator information.

When you created the /etc/shadow, you used a program called pwconv, there no equivalent program to create the /etc/gshadow file, but it really doesn't matter, it takes care of itself.

To create the initial /etc/gshadow file do the following:

touch /etc/gshadow
chown root.root /etc/gshadow
chmod 700 /etc/gshadow

Once you create new groups, they will be added to the /etc/group and the /etc/gshadow files. If you modify a group by adding or removing users or changing the group password, the /etc/gshadow file will be changed.

The programs groups, groupadd, groupmod, and groupdel are provided as part of the Shadow Suite to modify groups.

The format of the /etc/group file is as follows:

groupname:!:GID:member,member,...

Where:

groupname

The name of the group

!

The field that normally holds the password, but that is now relocated to the /etc/gshadow file.

GID

The numerical group ID number

member

List of group members

The format of the /etc/gshadow file is as follows:

groupname:password:admin,admin,...:member,member,...

Where:

groupname

The name of the group

password

The encoded group password.

admin

List of group administrators

member

List of group members

The command gpasswd is used only for adding or removing administrators and members to or from a group. root or someone in the list of administrators may add or remove group members.

The groups password can be changed using the passwd command by root or anyone listed as an administrator for the group.

Despite the fact that there is not currently a manual page for gpasswd, typing gpasswd without any parameters gives a listing of options. It's fairly easy to grasp how it all works once you understand the file formats and the concepts.

Consistency checking programs

pwck

The program pwck is provided to provide a consistency check on the /etc/passwd and /etc/shadow files. It will check each username and verify that it has the following:

  • the correct number of fields
  • unique user name
  • valid user and group identifier
  • valid primary group
  • valid home directory
  • valid login shell

It will also warn of any account that has no password.

It's a good idea to run pwck after installing the Shadow Suite. It's also a good idea to run it periodically, perhaps weekly or monthly. If you use the -r option, you can use cron to run it on a regular basis and have the report mailed to you.

grpck

grpck is the consistency checking program for the /etc/group and /etc/gshadow files. It performs the following checks:

  • the correct number of fields
  • unique group name
  • valid list of members and administrators

It also has the -r option for automated reports.

Dial-up passwords.

Dial-up passwords are another optional line of defense for systems that allow dial-in access. If you have a system that allows many people to connect locally or via a network, but you want to limit who can dial in and connect, then dial-up passwords are for you. To enable dial-up passwords, you must edit the file /etc/login.defs and ensure that DIALUPS_CHECK_ENAB is set to yes.

Two files contain the dial-up information, /etc/dialups which contains the ttys (one per line, with the leading "/dev/" removed). If a tty is listed then dial-up checks are performed.

The second file is the /etc/d_passwd file. This file contains the fully qualified path name of a shell, followed by an optional password.

If a user logs into a line that is listed in /etc/dialups, and his shell is listed in the file /etc/d_passwd he will be allowed access only by suppling the correct password.

Another useful purpose for using dial-up passwords might be to setup a line that only allows a certain type of connect (perhaps a PPP or UUCP connection). If a user tries to get another type of connection (i.e. a list of shells), he must know a password to use the line.

Before you can use the dial-up feature, you must create the files.

The command dpasswd is provided to assign passwords to the shells in the /etc/d_passwd file. See the manual page for more information.