Ch5 User and File Management
Ch5 User and File Management
Chapter 5
User and File Management
ITP3901 OPERATING SYSTEMS FUNDAMENTALS
(AY 2019/20)
REFERENCES:
HTTPS://ACCESS.REDHAT.COM/DOCUMENTATION/EN-US/RED_HAT_ENTERPRISE_LINUX/3/HTML/INTRODUCTION_TO_SYSTEM_ADMINISTRATION/S1-ACCTSGRPS-RHLSPEC.HTML
HTTPS://ACCESS.REDHAT.COM/DOCUMENTATION/EN-US/RED_HAT_ENTERPRISE_LINUX/4/HTML/INTRODUCTION_TO_SYSTEM_ADMINISTRATION/S2-ACCTSGRPS-FILES.HTML
HTTPS://LINUXFROMBEGINNING.WORDPRESS.COM/2008/09/20/LINUX-FILESYSTEMS-FILESYSTEM-HIERACHY-STANDARD/
2
User
Management
root can use the following command-line tools to help with account
maintenance.
useradd
passwd
usermod
userdel
groupadd
groupdel
groupmod
Option Description
-d <home directory> The new user will be created using <home directory> as the
value for the user’s login directory.
-e The date on which the user account is disabled, specify the date
in format YYYY-MM-DD
-G A list of groups of which the user is also a member (secondary
group membership).
-M The user’s home directory will not be created even if the default
is to create the home directory.
Remark: -l and -u options in passwd can be set to lock and unlock the user’s
account.
Chapter 5 - User and File Management ITP3901 Operating Systems Fundamentals
7
usermod
Option Description
-l <login name> Changes the user’s account name to <login name>. This does
not change the home directory of the user
e.g
[root@myLinux]#userdel john
[root@myLinux]#userdel –r student
Option Description
-g Permits the specification of the group ID number instead of using
the next-highest number defined by the system
To add a new group called support to the system, issue the following
command:
groupadd support
/etc/passwd
Contains an entry for each user on the system
e.g. root:x:0:0:root:/root:/bin/bash
/etc/group
Contains definitions of groups and their corresponding members
e.g. SDA2::502:student1,student2,student3
/etc/shadow
Stores account password information and contains password aging information
e.g. juan:$1$.QKDPc5E$8F.:11956:0:90:5:30:12197:
File Management
The basic function of a file system is to represent and organize the files in
hard disk.
Linux treats everything as a file
Processes (Running program)
Hardware devices
Interprocesses communication channels
The de facto file system on Linux is ext (or extended) file system. A
second version of this system was called ext2
Fedora 11 supports the latest version ext4.
Fedora currently supports other systems
msdos(DOS FAT)
ntfs (Windows)
iso9660 (CDROM)
hpfs (IBM OS/2)
ext3
Common Linux filesystem.
Journaling eliminates need for fsck
Beginning with the release of Red Hat Linux 7.2, the default file system
changed from the venerable ext2 format to the journaling ext3 file system.
ext2
Old Linux non-fragmenting fast filesystem.
Can be converted to ext3 by adding journal:
tune2fs –j /dev/sda1
ext4 (Fedora 11 changed the default file system from ext3 to ext4)
This directory contains everything required for the boot process. Thus
/boot/ stores data used before the kernel begins executing user-mode
programs.
The /dev/ directory contains file system entries which represent devices
that are attached to the system. These files are essential for the system to
function properly.
The /etc/ directory is reserved for configuration files that are local to the
machine.
This directory (/etc/sysconfig/) holds local system configuration
files (e.g. network card configuration files and graphics card configuration
file).
The /lib/ directory should contain only those libraries that are needed to
execute the binaries in /bin/ and /sbin/. These shared library images
are particularly important for booting the system and executing commands
within the root file system.
The /mnt/ directory is for temporarily mounted file systems, such as
CDROM/DVDROM and floppy disks.
/bin/
This directory contains executables for all users.
/sbin/
The /sbin/ directory is for executables used only by the root user (e.g.
shutdown command)
This directory (/var) contains files to which the system writes data during
the course of its operation
log files are stored under /var/log/
Both hard links and symbolic/soft links can be created using the ln
command.
While the –s option of the ln command creates a symbolic link, with no
option it creates a hard link.
e.g.
d means directory
Number of
- means file.
links
Everyone permission
Group ownership
Group permission
Owner of file
Owner permission
A hyphen(-) indicates that a particular permission is denied.
The chmod command is used to set the permission values for files and
directories.
The chgrp command is used to change the group settings of a file. It works
much like chown.
[root@myLinux]#chgrp student tutorial.doc
The –R option applies when the specified filename is a directory name.
[root@myLinux]#chgrp –R student tutdir
The fstab file contains the file system table, which is a table of all
disk partition, and their mount points and default mount options
Sample:
The third column in /etc/fstab specifies the filesystem type of the device
or partition.
The fourth column in fstab lists all the mount options for the device or
partition.
The 5th column in /etc/fstab is the dump option. Dump checks it and
uses the number to decide if a filesystem should be backed up. If it is zero,
dump will ignore that filesystem. If you take a look at the example fstab, the
5th column is zero in most cases.
The 6th column is a fsck option. fsck looks at the number in the 6th column
to determine in which order the filesystems should be checked. If it is zero,
fsck will not check the filesystem.
On each line is a seven field, colon delimited list which contains the
following information:
Username — The name the user types when logging into the system.
Password — The encrypted password for the user (or an x if shadow passwords are
being used).
User ID (UID) — The numerical equivalent of the username which is referenced
by the system and applications when determining access privileges.
Group ID (GID) — The numerical equivalent of the primary group name which
is referenced by the system and applications when determining access privileges.
GECOS — The GECOS field is optional, and is used to store extra information
(such as the user's full name). Multiple entries can be stored here in a comma
delimited list.
Home directory — The absolute path to the user's home directory, e.g.
/home/juan.
Shell — The program automatically launched whenever a user logs in. This is
usually a command interpreter (often called a shell). Under Red Hat Linux, the
default value is /bin/bash. If this field is left blank, /bin/sh is used. If it is
set to a non-existent file, then the user will be unable to log into the system.
e.g.
root:x:0:0:root:/root:/bin/bash
The /etc/group contains a list of system groups (and the group member).
Each line is a four field, colon delimited list including the following
information:
Group name — The name of the group.
Group password —Not used.
Group ID (GID) — The numerical equivalent of the group name. It is used by
the system and applications when determining access privileges.
Member list — A comma delimited list of users in the group.
e.g.
OSF::502:student0,student1,student2
Date password last changed — The number of days since January 1, 1970 that the
password was last changed. This information is used for the following password
aging fields.
Number of days before password can be changed — The minimum number of
days that must pass before the password can be changed.
Number of days before password change is required — The number of days that
must pass before the password must be changed.
Number of days warning before password change — The number of days before
password expiration during which the user is warned of the impending expiration.
Number of days before the account is disabled — The number of days after a
password expires before the account will be disabled.
Date since the account has been disabled — The date since the user account has
been disabled.
A reserved field — Not used.
e.g.
juan:$1$.QKDPc5E$8F.:11956:0:90:5:30:12197: