Common tasks and file locations on Red Hat Enterprise Linux
The command hostname will specify the current hostname.
The command “hostname server.example.com” will set the hostname to server.example.com.
To set the hostname to remain following a reboot the FQDN needs to be set in /etc/sysconfig/network. This setting is HOSTNAME=”server.example.com”
There are a number of tools within Red Hat Linux to set your IP address: netconfig, redhat-config-network and of course vi, emacs etc. The files are kept in /etc/sysconfig/network-scripts and the first ethernet interface file would be /etc/sysconfig/network-scripts/ifcfg-eth0
An example of this file with either dhcp set or with a permanent IP address follows:Permanent IP:
BOOTPROTO=dhcpIt is possible to refresh dhcp settings by executing “ifup eth0″To set a virtual IP address the files are similar: /etc/sysconfig/network-scripts/ifcfg-eth0:0 is the first and the directive for the DEVICE within the file should reflect the device being set i.e. DEVICE=eth0:0 You can also use “redhat-config-network” or “netconfig -d eth0:0”
To set a gateway you can use the command line “route add default gw 192.168.0.1”. This will not remain after a reboot, the entry should be entered in the file “/etc/sysconfig/network” with the setting “GATEWAY=192.168.0.1” then executing “service network restart” will install the default route and refresh the network settings.
This may be set in the file /etc/sysconfig/network “NETWORKING_IPV6=yes”
NIS Domain name
The command domainname will provide the current NIS domain. The NIS domain may be set using this command too i.e. “domainname cupboard” would set the current NIS domain to the value of cupboard. I suggest not using the company name for the NIS settings as there is a little value in “security through obscurity”, but not a lot.
The file that contains the NFS shares on Linux is /etc/exports. “man exports” will provide a lot of information. The basic format is similar to a lot of other UNIX systems. Each line has the share, then the host(s) then the permissions: “/home/exports *.example.com(ro) 192.168.0.0/24(rw,insecure)”. Please note that the insecure option is required if you want Mac OS X. Mac users are able to make mounts and as a consequence the mounts come from ports which are considered insecure.
Add a user
Adding a user may be done using a number of tools: useradd, adduser, vipw, redhat-config-users. vipw provides access to the password file and does ‘some’ sanity checking on the root account on the password file; however it will probably be much easier to use a tried and tested tool such as useradd. useradd creates the entry in the /etc/passwd file, it creates the home directory, it copies all of the files from /etc/skel/ to the users home directory and then adds a group for the user, normally with the same name of the user. After adding the user you may want to set the user’s password, without this they will not be able to log in. Please note that if you need to set up users without a password (and hence without an interactive account on the machine) then you need to use useradd or adduser. redhat-config-users requires a password to be set.
Change a password
“passwd user” as root will change a password. It may give a warning that the password is poor; however it will still allow a poor password to be set. “passwd” as user will allow a normal user to set their password; however by default it will be checked to ensure that it is a secure password. This will not work if ypbind is running i.e. if NIS is being used. It may be possible in this case to use yppasswd; however only if the service yppasswd is running.
Lock / Unlock an account
An account may be locked or unlocked using “usermod -L user”, you can also use “passwd -l user”. To unlock an account “usermod -U user” or passwd -u user” may be used.
Change password defaults
The defaults for passwd ageing are found in /etc/default/useradd. These may be read using “useradd -D” and then set with “useradd -D -f 30”, which would set an account which had been inactive for 30 days to be locked. The man page is very helpful.
The X configuration file is /etc/X11/XF86Config it may be edited by hand; however you may find it much easier to run redhat-config-xfree86. If there is no configuration file then moving to runlevel 5 will automatically start redhat-config-xfree86.
To change the current runlevel you can use the init command: “init 5” will take you from the current runlevel to runlevel 5. To discover your current runlevel, typing “runlevel will tell you the previous runlevel and current runlevel. There are 9 available runlevels; however only runlevels 1-6 are configured by default. The default runlevel used at boot in stored in the file /etc/inittab, the line that sets the run level is: “id:5:initdefault:”The default runlevels set are as follows:
0 – halt (Do NOT set initdefault to this)
1 – Single user mode
2 – Multiuser, without NFS (The same as 3, if you do not have networking)
3 – Full multiuser mode
4 – unused
5 – X11
6 – reboot (Do NOT set initdefault to this)
The default shell for Linux is normally the bash shell. There are a number of very useful features with bash:
the TAB key will try to complete your sentences, by looking at what you are typing so “vi /etTABsyscoTABnetwTAB-TAB” becomes “ls /etc/sysconfig/network-scripts/”. This has the advantage that you can check the spelling of paths that you are typing as you proceed.
If you use the command “history” it will print out all your previous commands. You can also use the up, down, left and right arrow keys to edit your commands. You do not have to be at the end of a line when you press enter to have the command accepted.Other shells available include korn, C, ash, tcsh and perl.
vi, emacs etc. etc. Please note that there are many text editors available. vi is the default. vi is actually aliased to vim and as a result you can use page-up, page-down and the arrow keys when in command or edit mode, please try it – it is very friendly
Recover a root account
Move the system to runlevel one in grub; at boot the grub menu will state “press e to edit”; press e and then choose the line with kernel on it; press e to edit again and move to the end, pressing the end key; enter a space and the digit “1”; press enter and then “b” to boot. This will take you to a command prompt where you can unlock the account or change your password.
Add a disk
ide disks are labelled as follows primary master: /dev/hda, primary slave: /dev/hdb, secondary slave: /dev/hdc
SCSI disk are labelled as follows, first SCSI hard disk: /dev/sda, second: /dev/sdb
SCSI cdroms are labelled as follows, first SCSI cdrom: /dev/scd0
Note that SCSI devices will be renamed as peers on the same controller are removed; hence it may be better to label SCSI devices using devlabel. SCSI devices are not auto-detected as they are added; there is a third party script available which will query the SCSI chain and enter the correct values in /proc
Partition a disk
fdisk -l will show all partitions on all devices
To create a new partition on a the first SCSI disk you can use fdisk /dev/sda. Please note that the first partition on this disk would be /dev/sda1 but with fdisk we would address the disk as a whole. sfdisk is also available, which has the advantage of being script-able.
Format a file system
The default filesystem for Red Hat Linux is ext3. This is a journalised filesystem, which recovers from disk crashes (such as unexpected power failures) much faster and is more likely to maintain data than a non-journalised filesystem. There are other filesystems available for Linux, these include ext2, xfs, reiserfs and jfs.To format the second partition on the third SCSI disk the command would be: “mkfs.ext3 /dev/sdc2”. Using the auto-completion with the bash shell mkfsTABTAB would provide a list of format commands. It is also possible to use “mkfs -t ext3 /dev/sdc2”
Ensuring that a service is started after reboot
The services are stored in the directory /etc/rc.d/init.d/ these may be controlled using chkconfig, ntsysv and redhat-config-services. Please note that ntsysv and redhat-config-services use the current runlevel by default; however you can change this e.g. “ntsysv –level 345” which would make changes to runlevels 345. chkconfig is probably the easiest, you can use “chkconfig httpd on”, which would set apache to start in runlevels 3,4 and 5.
Installing software and using rpm
There are a number of functions that are normally done with software: install, remove, upgrade and query what is installed.
Install software: “rpm -ivh newsoftware-1.0.rpm” or “rpm -ivh /home/xander/newsoftware-1.0.rpm”; note that rpm expects to address the rpm in the same directory or a specified path to the rpm, in addition the full path to the software should be specified.
Remove software: “rpm -ev newsoftware”. Note here we just specify the software package, not the rpm name.
Upgrade software: “rpm -Uhv newsoftware-1.2.rpm”
There are lots of methods to get help:
Man pages: “man CommandThatYouWantInfoOn”, try “man man” for help on manual pages
There are many different manual sections:
Section 1 User Commands
Section 2 System Calls
Section 3 Subroutines
Section 4 Devices
Section 5 File Formats
Section 6 Games
Section 7 Miscellaneous
Section 8 System Administration
Section 9 Kernel
Section n New
For an idea on the differences try the following: “man crontab” and then “man 5 crontab”, note in the second command that there were a number of examples. The section chosen was section 5 which is file formats. Always have a look out for man section 5 when dealing with configuration files. It is always a good idea to include documentation with applications, there is a useful tool to create man pages called manedit available here: http://wolfpack.twu.net/ManEdit/
Info pages: “info CommandThatYouWantInfoOn”
Other users: Linux enthusiasts and users frequently have very deep technical knowledge on a myriad of subjects. They also frequently work with Solaris, Irix, AIX and other UNIX systems, consequently Linux User Groups (LUGs) are superb sources of information and entertainment. For your local user group see http://www.linux.org/groups/