URL.biz - where people find experts

 
HOME ARTICLES LIST NOW FOR FREE! ABOUT US CONTACT US LOG IN

Unix Fundamental Course Module #2 System Access
Second in a series of Unix Fundamentals modules from JayrConsulting Ltd. A FREE copy of this module in MsWord format (including missing diagrams) can be got from john.roberts@jayrconsulting.co.uk

Go to Web Site

UNIX Fundamentals

MODULE 2 – Accessing the UNIX System



You will cover

* UNIX Directory structure

* File Path names

þ Files used during login sequence

þ Changing user identity

þ Checking on files and disks for space used

þ Changing Terminal settings

þ Changing passwords









































































































MODULE 2 – CONTENTS

2.1 DIRECTORY STRUCTURE 4

2.1.1 DIRECTORIES AND FILES 4

2.1.2 SYSTEM DIRECTORIES 5

2.2 PARTITIONS AND FILE SYSTEMS 6

df command 6

du command 6

2.3 UNIX FILE PATH NAMES 7

2.4 NAVIGATING AROUND DIRECTORIES. 8

2.4.1 LOGIN PROGRAM SEQUENCE 8

2.5 USING OTHER USER ID'S 9

2.5.1 SUPERUSER LOGIN 9

2.5.2 SWITCHING BETWEEN USER ID'S 9

2.5.3 SWITCHING BACK 9

2.6 CHANGING PASSWORDS 10

2.6.1 CHANGING GROUPS 10

2.6.2 CHANGING TERMINAL SETTINGS 11

2.7 ACCESSING FILE INFORMATION WITH LS 12

2.7.1 OTHER OPTIONS WITH LS 13

2.8 INFORMATION COMMANDS 13





2.1 Directory Structure













































2.1.1 Directories and Files

Directories and files on UNIX systems are arranged in an inverted ‘tree' structure, similar to an organisational chart. Some of the files and directories are standard and will be found on all UNIX systems. Other parts of the structure will be site specific and will be governed by local requirements and the applications that are installed.

The initial entry point to the system is the ‘root' directory, normally signified with a ‘/', with all other files and directories being arranged below this.

When a user logs on to a UNIX system, they are placed at a pre-designated directory, usually beneath the system ‘home' directory. This directory is often referred to as the users ‘home' directory.





2.1.2 System Directories

The following is a description of some of the standard directories found on most UNIX systems.

/ The root directory. All other files on the system can be located by giving a path starting from the root directory.

bin Directory containing binary executable files as system commands.

sbin Directory containing further system admin commands.

etc Directory containing system maintenance files.

lib Directory containing program library files, such as sub-routines for the ‘C' programming language.

usr Directory containing user service routines. Usually has additional ‘bin' and ‘lib' sub directories.

tmp Directory containing temporary files, that are typically cleared on system shutdown/reboot.

dev Directory containing special device files. These are used for interfacing with I/O devices, such as disks, tapes, printers etc.

home Usually the starting point of sub structure containing users default login directories.



















2.2 Partitions and File Systems

The UNIX directory system is usually split into file systems. Each file system is allocated to a partition on disk. The root partition will contain all the main system directories, such as ‘etc', 'bin',' sbin' and ‘dev'.



















df command

Information about disk partitions and file systems can be displayed using the df command. ( or ‘bdf' on some systems )



df –k shows disk space used in Kbytes and as percentage of capacity



Other options with df show more detailed information on disk usage

du command

The du command displays disk block usage information on a directory or file basis.



du /home would show block count for directories under /home



du –a /home would show block count for all files under /home

2.3 Unix File Path Names

UNIX always knows the location of the ‘root' directory file. To locate any other file, the system must be told which route to follow, through the tree structure. There are two methods that can be used. These are ‘Full Pathnames' (sometimes called ‘Absolute Pathnames'), which start from the root directory each time, or ‘Relative Pathnames' which start from the directory you are in at the time. (current directory)

All UNIX directories contain two pointers ‘.' and ‘..' .These point to the current directory and parent directory, respectively.























With reference to the tree structure shown above, it is assumed that a user has a current directory of ‘files'. Files on the system could be accessed by ‘Full' or ‘Relative' pathnames as follows.

/home/anna/files/pbox full pathname to access file ‘pbox' in directory ‘files'

pbox or ./pbox relative pathname to same file

../bin/trans relative pathname to file ‘trans' in directory ‘bin'

/home/anna/bin/trans full pathname to same file



2.4 Navigating around directories.

Moving around the directory structure is effected by use of the ‘cd' command as follows.

cd directory_name would move you to that directory

cd /var/adm would place you at the directory /var/adm

cd on its own will always put you back to your initial login directory

2.4.1 Login program sequence

Several files are consulted during the logging in process.

When a user has successfully logged on to the system, the login program is replaced by the shell program, typically ‘/usr/bin/ksh'. Logon attempts are validated by a file called ‘/etc/passwd', which functions as the accounts file on a UNIX system. Many UNIX systems also employ a file called ‘/etc/shadow', in which the actual password information is stored, for added security. Password information is always encrypted in these files, for security reasons.

The Korn shell program initialises it's own and the user's environment by reference to a file called ‘/etc/profile' and a file called ‘.profile' (in the user's home directory ) and then presents the user with the command prompt. ( ‘C' shell uses ‘.login' and ‘.cshrc' files instead )

During the above sequence, several files may be accessed and information displayed on the terminal screen. The exact sequence and content of this information is system dependent and may be altered by the system administrator, but typically will be contents of ‘/etc/motd', ‘/var/news' etc.













2.5 Using other user id's

There are other user id's on a UNIX system. Many of these are used purely for file ownership purposes, such as ‘bin', ‘sys' and ‘adm'.

2.5.1 Superuser login

The ‘root' login, also known as the ‘superuser', is the most privileged and powerful account on the system. There are no restrictions on the ‘root' account, giving it total access to all files and processes on the system. Normally the ‘root' account can only be logged onto directly, via the system console. When logged on to the root account, the system displays the ‘#' prompt.

2.5.2 Switching between user id's

A user can change to other user id's, providing the requisite password is known, by using the ‘switch user' command ‘su' as shown below.

su username changes your current ‘uid' and ‘gid' numbers to that of the nominated user, but leaves the current working directory and environment.

su – username as above, plus changes directory and working environment completely to that of the nominated user.

su changes ‘uid' and ‘gid' to that of ‘root'

su – as above, plus changes directory and working environment completely to that of ‘root'

Note : On some systems all executions of the ‘su' command, whether successful or not, are logged in the administration file ‘/var/adm/sulog'

2.5.3 Switching back

To switch back to your own user id, you should enter at the command prompt. DO NOT use ‘su' to switch back, as this will open another process on the system, leaving your previous shell process still running.



2.6 Changing Passwords

To associate a password with a login or to change a password assigned previously, the passwd command is used. All users have the ability to change their own password, but only superuser can change other users passwords without having to know what the original password was .

passwd allows user to change own password

passwd user1 would allow superuser to change password

Passwords must be constructed to meet certain requirements. These vary according to UNIX type but may include some of the following :

(1) A password must have at least six characters

(2) Characters must be from the 7-bit USASCII character set with letters from the English alphabet.

(3) A password must contain at least two uppercase and/or lowercase letters and at least one numeric or special character.

(4) A password must differ from the user's login name and any reverse or circular shift of that login name.

(5) A new password must differ from the old one by at least three characters.

The following typical example would force user2 to establish a new password on the next login that will expire in 70 days and prohibit the user from changing the password until 7 days have transpired:

passwd -f -x 70 -n 7 user2

where ‘x' = maximum days, n = minimum days and ‘f' = force change at next log in time.

2.6.1 Changing Groups

Although a user can only have one primary group identity at one time, it is possible to belong to several secondary groups. An entry must exist in the file /etc/group for each group that a user belongs to. A user can then switch between groups by using the newgrp command, as follows.

newgrp admin would change the group identity of the user to ‘admin'



2.6.2 Changing Terminal Settings

The stty command is used to set the attributes and options for a terminal. It can also be used to display the current settings if used without any arguments.

stty displays short list of current settings

stty –a displays complete list of all parameters.

stty erase <^H> set erase key to be ‘CTRL-H'

stty intr <^A> set interrupt key to be ‘CTRL-A'



2.7 Accessing File Information with ls

The ls command lists information about files. If no argument is given, the current working directory is assumed. There are various options which alter the display of information given.

With reference to the above display created by executing the command ls –l .



A = file type

B = access permissions for user (owner)

C = access permissions for people in same group

D = access permissions for others

E = number of links to file

F = user name of file owner

G = group name of file owner

H = size of the file in bytes

J = date and time of last modification

K = file name



2.7.1 Other options with ls

There are many other options that can be used with ls, to extract information about files on the system. For example, ls –R would produce a recursive file listing, starting at the current directory, while ls –i would list all files in the current directory along with their respective ‘inode numbers'



ctatrnr@dopey> ls -i

190424 memo

190419 CUSTOM.ksh

192000 bin

190428 change_local_user.shl

190431 copy.in

2.8 Information Commands

The following are some of the commands that can be used on the system. Further information about the commands and their options should be obtained from the on-line manuals.

cat filename display contents of file on screen

pg filename display file contents, a page at a time

who list information about logged on users

finger list information about logged on users



last historical list of logins, showing who where, and when

pwd shows current directory

uname –a shows information about the machine






 
Other Articles Written By This User


Copyright © 2003 - 2012 URL.biz. All rights reserved.