Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 31

Linux Server Administrator Guide

(1)Kernel
(2)Shell
(3)Programmes/utilities

Although operating system usually regarded


with all three layers, strictly speaking,
programmes/utilities are not part of the
operating system. Programmes/Utilities that
come with the operating system is a
supplement to standard UNIX command, then
makes the system more useful to the user, but
only the kernel and the shell are truly the
operating system.
Kernel 
The kernel is the core of operating system,
presenting a virtual machine interface to
user process. Processes are written without
needing any knowledge of what physical
hardware is installed on a computer. Instead
the kernel abstracts all hardware into a
consistent virtual interface. The kernel
provides low-level services:
- Access to hardware (I/O)
- Memory management
- Process management
- Inter process management
- Virtual file system switch
Kernel Sub-System
Shell
• A UNIX shell provides the user interface for
the UNIX operating system. Shell runs by the
login process. Shell interprets user
commands, executes them and returns to the
shell. Shell can be customized through shell
environment variable.
• There exist a number of shell registers in
/etc/shells. You can select one of shells
using chsh, or passwd –s command. Environment
variable, “SHELL” shows current shell you are
using. Below are well known shell:-
Shells
• Bourne shell (sh) 
• It is written in Bell Laboratory in 1977. At first it was
distributed with Version 7 UNIX. 
C shell (csh) 
• It is written for the BSD UNIX system, derived from the
predecessor, "the Bourne shell" C like syntax.
Bourne-again shell (bash) 
• This is the default shell on most Linux systems. Written in
1987 by Brian Fox in 1990, it is a pun on the Bourne shell
(sh), which was an early, important UNIX shell. The Bourne
shell was the shell distributed with Version 7 Unix.
TENEX C shell (tcsh) 
• It is based on and compatible with the C shell (csh). It is
essentially the C shell with 
• (programmable) filename completion, command-line editing, and
a few other features.
User Management
• UNIX is multi user operating system. It is
necessary to differentiate between the users
so as to keep the file system private, or
assign the right permission, and whatever.
Each user is given an account: set of files
which is usually stored in the user home
directory, resources, and information
belonging to a user
• /etc/passwd
• The /etc/passwd file contains user account’s
attributes.
• Login name
• Encrypted password
•  UID (User ID)
•  GID (Group ID)
•  GECOS (Generic Electric Comprehensive
Operating System) field for general
information. Normally it contains real name
• Home directory location
• Default shell
Example
root:x:0:0:root:/root:/bin/sh
user1:x:1000:100:User1:/home/user1:/bin/bash
user2:x:1001:100:User2:/home/user2:/bin/bash
/etc/group
 
 Group information is stored in /etc/group. 
 Group name
 Password (rarely used)
 GID (Group ID)
 List of members GECOS (Generic Electric
Comprehensive Operating System)
 Home directory location
 Default shell
Example
• root:x:0:
• users:x:100:
Account Management Utilities

• There are some command line utilities in relation to


managing users, and groups. useradd, usermod, userdel,
passwd : operate on the /etc/passwd filegroupadd,
groupmod, groupdel : operate on the /etc/group file
useradd is mostly used command. To create a new user
“user1”, simply type,
# useradd user1 –m –g users
• The option –m create home directory, and –g option
specify the group. 
• Then, following entry will be added in /etc/passwd.
This default value was derived from 
• /etc/default/useradd. 
• user1:x:1005:100::/home/user1:/bin/bash
• The default values can be overridden by
specifying additional values. In the next
example, primary and secondary group, home
directory location and default shell are
specified. 
• To add group networkgroup using groupadd
command: 
• # groupadd networkgroup1 
• # groupadd networkgroup2 
• Next, add a user called nwstudent to group
networkgroup: 
• # useradd –G networkgroup1 nwstudentA
• We can add user user1 
# useradd –c "User1" –d /home/writer/user1 –g
networkgroup1 –G  networkgroup2 –s /bin/tcsh -m
user1
• Then this command created the following passwd
entry:
user1:x:1005:100:User1:/home/writer/user1:/bin/tcsh

• To change own password,


• # passwd
• Changing password for root. New Password:
• Reenter New Password:
• To change a user’s password
• # passwd user1
• Changing password for user1. New Password:
• Reenter New Password: 
• Password changed.
File System
• Most of the hard disks are mounted automatically.
When you boot Linux, all Linux partitions residing on
hard disk that are listed in the /etc/fstab file are typically
mounted.
• To see file system types that are currently available to be
used on the system, type, 
• # cat /proc/filesystems
Type Description
cifs Common Internet File System (CIFS), the virtual file system used
to access servers that comply CIFS specification. CIFS is an
attempt to refine and
standardize the SMB protocol used by Samba and Windows file
sharing.
ext4
Ext file systems are the most common in Linux systems. Ext4
is now the default file system for the Linux partitions. ReiserFS, JFS,
XFS, Ext4 and Ext3 are journaling file systems. These file systems are
able to restore the system very quickly after a system crash, utilizing
write processes logged during the operation. The main benefits that
ext4 has over ext3 are: faster time stamping, extents (basically automatic
space allocation to avoid fragment, faster file system
checking, and journaling checksums.

ext3 The ext3 file system includes journaling features that


 
compared to ext2,
improve a file system’s capability to recover from crashes.
ext2 The default filesystem type for earlier Linux system. Ext2 does
 
not include
journaling features.
msdos An MS-DOS filesystem. You can use this type to
 
mount floppy disks that
come from Microsoft OS.

vat Microsoft extended FAT (VFAT) filesystem


reiser ReiserFS journaled filesystem. ReiserFS and ext4,
fs  
are the most common
filesystem types used with Linux today.

swap Used for swap partitions. Swap areas are used to hold
 
data temporarily when
RAM is currently used up.

nfs Network File System (NFS) type of filesystem. NFS


 
is used to mount file
systems on other Linux or UNIX computers.

ntfs Windows NT filesystem. It is supported as a read-only


 
file system. Read-write
support is available but considered unreliable.
  Path Contents

/(root)    
  /bin location of user command & utilities, which are binary
files
  /boot kernel and files needed to load the kernel

  /dev device directory, device file, terminal

  /home location of user ‘homes’

  /lib Libraries that are used by various programs and languages.

  /media mount points for removal media (new FHS)

  /mnt used previously as mount points for removal media

  /opt optional, add-on application software packages

  /proc ‘process directory’ – files corresponds to running process

  /root location of ‘home’ of user ‘root’

  /sbin ‘system’ command

  /srv Data directory for http and ftp servers


  /tmp temporary or scratch

  /usr application programmes, on-line manual pages, language dictionary

    /bin command and executable

    /include Header files for C programmes

    /lib libraries

    /local software you compile and installed from source code

    /sbin less essential commands for system administration

    /share items that might be common for system administration

    /src source code (non-local) software packages

  /var log files, process ID, application programme’s configuration files

    /log system log files

  /etc system configuration files

    /init.d location of start-up shell scripts

      /rc1.d start-up-files for single user mode

      /rc3.d start-up-files for multi user text mode

      /rc5.d start-up-files for multi X11mode


File Permission

• The chmod command changes the permission


of a file. Only the owner of the file and
super-user can change its permission.
• # chmod 'access-control' file(s)

• ▪ u(user), g(group), o(others), a(all) 


• ▪ +(add), -(remove), =(exact) 
• ▪ r(read), w(write), x(execute) 
• or octal digit listed right
Example
• # chmod 754 Script 
• This is equal to 
• # chmod u=rwx,g=rx,o=r Script 
• This will add group write permission to myDir and all
its contents 
• # chmod –R g+w myDir

• The chown command change a file’s, or directory’s


ownership, and group ownership. To change a files’
group, you must wither owner of the file and belong to
the group, or super user. To change owners of files,
you must be the super user (root).
Example
• # chown new-owner files(s)
• # chgrp new-group files(s)
• As well as chmod, chown with –R flag changes the
settings of a directory, and all the files
underneath.Check existing owner,
• # useradd –g networkgroup1 –m user1 
• # cd /home 
• # ll 
• drwxr-xr-x 7 user1 networkgroup1 4096 Dec 29 15:59
user1
•  # cd user1
•  # ll total 44
• -rw-r--r-- 1 user1 networkgroup1 1028 Dec 29 15:59
.profile
Link Files (Hard Link and Soft Link)
• The design of inode makes easy for a file to have more
than one name, simply by having more than one link
pointing to the same inode. The links might be in the same
directory or in different directories. The command ln
(link) creates a new link to an existing file.
• # ln original.txt hardlink.txt
• It creates a second link called hardlink.txt that points
to the same file as original.txt. There is still only one
copy of the file. This link is called hard link. You have
two links (of exactly equal status) pointing to the same
file. The file has two names.
•  There is also a special file type called a symbolic link,
also known as a symlink, or soft link. A symlink is just a
small file that contains the name of some other file. From
the shell you can create symlink using ln -s. For example,
• # ln –s original.txt softlink.txt
• It creates a symlink called softlink.txt that points to the
link original.txt (as opposed to a hard link, which would
point to the same inode that original.txt points to). A
symlink is like a shortcut in Windows.
•  Note that if you want to create a symlink at another
directory, use the full pathname of the
• original. For example, 
• # ln –s /home/user1/original.txt /home/user1/test/softlink.txt
• As result,
• # ll *.txt -i
889711 -rw-r--r-- 2 root root 8 2007-06-03 13:08 hardlink.txt
889711 -rw-r--r-- 2 root root 8 2007-06-03 13:08 original.txt
889689 lrwxrwxrwx 1 root root 12 2007-06-03 13:09
softlink.txt -> original.txt
Mounting and Un-mounting File Systems
•  All file systems are logically contained
within the root directory / (root), regardless
of their physical location. The system mounts
/ (root), and unmount / (root) (usually
/mnt).To mount the file system,
• # mount [-t type] [device] directory [-o
options]
•  To mount a CD Drive 
• # mount –t iso9660 /dev/cdrom /media/cdrom 
• Or just 
• # mount /dev/cdrom /media/cdrom
• To mount an ISO file 
• # mount /tmp/openSUSE.iso /mnt/suse -o loop
• To un-mount the file system, 
• # umount directory
• 
• To verify the mounted filesystem,
•  # df
Using fstab File to Define Mountable File
Systems
• /etc/fstab file contains reference to frequency mounted
file system. Also, simplify the mount command usage.
Checking Files
•  (1) Displaying System Space with df
•  You can display the space available in your
file systems using df command. To see the
amount of space available on all the mounted
file systems on your Linux. To produce output
in a more human-readable form, use –h option.
• df
• df –h
• Check the same filesystems for inode
utilization. 
• df –i
Checking Disk Usage with du
• 
• To find out how much space is being consumed by a
particular directory and its sub directories use du command.
Using –h option print sizes in human readable format (i.e. 1K,
• 2M, 3G).

• # du -h /var/log/ 
• 96K /var/log/gdm 
• 4.0K /var/log/apache2 
• 1.1M /var/log/delegate-old 
• 8.0K /var/log/smpppd

• Using –s option summarize the display only a total for each


directory.
• # du -sh /usr/*
Search for files in a file system with find

•  Find file named core in or below directory /


•  # find / -name core –print
• Find file named with a wildcard, it should be
enclose the pattern in quotes.
• # find /usr/local/src -name '*.c' -print
• Find files which is more than 100M file size
in or below directory /home
• # find /home -size +100M –print
• Find files owned by username (or numeric user
ID) in or below directory /
• # find / -user username –print
Search for files in a file system with
locate
By installing the findutils-locate package,
files can be found quickly by the file name.
This tool creates the filesystem database
which is updated daily. When you install
the package, the database is not created.
The first time, or when you want to
update the database, execute as,
• # updatedb
• Find files by filename as, 
• # locate filename

You might also like