0% found this document useful (0 votes)
2 views

unix 2nd unit

Unix operating system

Uploaded by

Akansha S
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

unix 2nd unit

Unix operating system

Uploaded by

Akansha S
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

UNIT -II

Types of user accounts


1. Super User: This account is also known as the root account. It has all the
permissions and can run all the commands without any restriction. The
keyword sudo is often used to run a command as the root user.
2. Normal User: The general users of the system are assigned this account. This
account has restricted access to the commands and files of the system. The root
user can create such an account, modify its permissions or delete it.
3. System User: This is the type of account that is created only for a specific purpose
or software. For example, a mail account.

Creating a user account

To create a normal user account, we use the useradd command, like shown in the following
snippet of code:

sudo useradd [options] [username]

In the above snippet, the username is the name by which we will create the new account.
Note that the name can not be the same for two users.

In the place of options, we can pass different flags to enable or disable different settings.
The following table contains those options and their brief descriptions:

Option Description
-b, --base-dir BASE_DIR This option is used to specify the default base directory for
the new user being created. BASE_DIR is concatenated with
the account name to specify the base directory if the -d flag is
not used to define the home directory.
-c, --comment COMMENT This option is used to write a short description of the new
account. It is also used as the user's full name for the time
being.
-d, --home HOME_DIR This option is used to specify the home directory for the
newly created user.
-D, --defaults This option is used to display the current default values for
the `useradd` command
-e, --expiredate This option is used to specify the date in the YYYY-MM-DD
EXPIRE_DATE format on which the newly created user account will be
disabled.
-f, --inactive This option is used to specify the number of days that the
account will stay active after its password has expired.
-g, --gid GROUP This option is to specify the name or number of the group of
newly created user.
-G, --groups This option is used to specify a list of groups which will be
Group1[,Group2,... joined by the newly created user.
[GroupN]]]
-h, --help This option is to display the help message
-k, --skel SKEL_DIR This option is used to specify files and folders which will be
copied into the home directory of the newly created user.
-K, --key KEY=VALUE This option overrides the default values present in
/etc/login.defs. These inclue UID_MIN, UID_MAX, UMASK
etc.
-I, -no-log-init This option prevents the user to be added from the lastlog
and faillog databases.
-m, --create-home This option is used to create the user's home directory if it
does not exist.
-M This option is used to prevent the creation of the home
directory.
-N, --no-user-group This option is used to prevent the creation of a group with the
user's name.
-o, --non-unique This options allows the creation of a user account with a
duplicate ID.
-p, --password PASSWORD The encrypted password, as returned by the `crypt`.
-r, --system This option is used to create a system account.
-s, --shell SHELL This option is used to specify the name of the user's login
shell.
-u, --uid UID This option is used to set the numerical value of the user' ID.
This value must be unique.
-U, --user-group This option enables the creation of a group with the same
name as the user's name.
-Z, --selinux-user SEUSER This option is used to determine the SELinux user for the
user's login.

Modifying a user account

To modify a user account, we use the usermod command as shown in the following snippet:

usermod [options] [username]

In the above snippet, the username is the name of the account that is to be modified.

In the place of options, different flags are passed for different settings.

Deleting a user account

To delete a user account, we use the userdel command as shown in the following snippet:

userdel [options] [username]

In the above snippet, the username is the account’s name that is to be dIn order to find
differences between these two types of links we first have to define them:

Symbolic Link:

The easiest way to understand what a symbolic link is in Linux is to compare it to the
“direct link” or “shortcut” in Windows. The file or directory is located at a single point on
the disk and the links are a pointer against it. Each symbolic link has its own inode number
which allows symbolic links to be made between different file systems.

To create links (both symbolic and hard links) we use the command ln. In this case, we will
create a symbolic link (parameter -s) from the test file:

$ ln -s test link-to-test

Hard Link:

The hard links are to associate two or more files sharing the same inode. This makes each
hard link an exact copy of the rest of the associated files, both data and permissions,
owner, etc. This also implies that when changes are made to one of the links or to the file,
these changes will also be made to the rest of the links.

Hard links cannot be made against directories or outside the file system itself.

We are going to create a hard link against the “test” file before and we will see that they
effectively share inode and that the data is synchronized between both:

$ ln test link-hard-test
$ ls -li

In the place of options, different flags are passed for different settings.

Groups

In Unix-based operating systems, we can form groups of users’ accounts. Groups are used
to manage the user accounts collectively. We can manage the access permissions for the
entire group.

A single user can be a part of multiple groups, and a group can have multiple users.

The terminal commands related to groups are discussed in detail below.

Creating a new group

We use the groupadd command to create a new group, as shown in the snippet below.

groupdadd [options] [groupname]

In the above snippet, groupname is the name assigned to the newly created group.

In place of options, we can pass different flags for different settings.


Modifying a group

We use the groupmod command to modify an existing group, as shown in the snippet
below.

groupmod [options] [groupname]

In the above snippet, groupname is the group’s name that is to be modified.

In place of options, we can pass different flags for different settings.

Deleting a group

To delete a group, we use the groupdel command as shown in the following snippet:

groupdel [groupname]

In the above snippet, groupname is the group’s name that is to be deleted.

What is granting rights in Unix?

Every file in Unix has the following attributes − Owner permissions − The owner's
permissions determine what actions the owner of the file can perform on the file. Group
permissions − The group's permissions determine what actions a user, who is a member of
the group that a file belongs to, can perform on the file.

What is user management command?


User account properties, such as usernames, UIDs, GIDs, home directories, default shells,
and passwords. User management tasks, including creating, deleting, and modifying user
accounts with the use of commands like useradd , userdel , and usermod.

File quota ?
A disk quota is the amount of space allotted to each user for file storage on a given
computer. On shared systems such as Unix, every user has a maximum disk quota. This
prevents any individual from using more than his or her fair share of disk space.

Unix File System



Unix File System is a logical method of organizing and storing large amounts of information
in a way that makes it easy to manage. A file is the smallest unit in which the information is
stored. Unix file system has several important features. All data in Unix is organized into
files. All files are organized into directories. These directories are organized into a tree-like
structure called the file system. Files in Unix System are organized into multi-level
hierarchy structure known as a directory tree. At the very top of the file system is a
directory called “root” which is represented by a “/”. All other files are “descendants” of
root.

Types of Unix Files


The UNIX files system contains several different types of files

Ordinary Files
An ordinary file is a file on the system that contains data, text, or program instructions.
● Used to store your information, such as some text you have written or an image
you have drawn. This is the type of file that you usually work with.
● Always located within/under a directory file.
● Do not contain other files.
● In long-format output of ls -l, this type of file is specified by the “-” symbol.
Directories
Directories store both special and ordinary files. For users familiar with Windows or Mac
OS, UNIX directories are equivalent to folders. A directory file contains an entry for every
file and subdirectory that it houses. If you have 10 files in a directory, there will be 10
entries in the directory. Each entry has two components. (1) The Filename (2) A unique
identification number for the file or directory (called the inode number)
● Branching points in the hierarchical tree.
● Used to organize groups of files.
● May contain ordinary files, special files or other directories.
● Never contain “real” information which you would work with (such as text).
Basically, just used for organizing files.
● All files are descendants of the root directory, ( named / ) located at the top of
the tree.
In long-format output of ls –l , this type of file is specified by the “d” symbol.
Special Files
Used to represent a real physical device such as a printer, tape drive or terminal, used for
Input/Output (I/O) operations. Device or special files are used for device Input/Output(I/O)
on UNIX and Linux systems. They appear in a file system just like an ordinary file or a
directory. On UNIX systems there are two flavors of special files for each device, character
special files and block special files :
● When a character special file is used for device Input/Output(I/O), data is
transferred one character at a time. This type of access is called raw device
access.
● When a block special file is used for device Input/Output(I/O), data is transferred
in large fixed-size blocks. This type of access is called block device access.
For terminal devices, it’s one character at a time. For disk devices though, raw access
means reading or writing in whole chunks of data – blocks, which are native to your disk.
● In long-format output of ls -l, character special files are marked by the “c”
symbol.
● In long-format output of ls -l, block special files are marked by the “b” symbol.
Pipes
UNIX allows you to link commands together using a pipe. The pipe acts a temporary file
which only exists to hold data from one command until it is read by another.A Unix pipe
provides a one-way flow of data.The output or result of the first command sequence is used
as the input to the second command sequence. To make a pipe, put a vertical bar (|) on the
command line between two commands.For example: who | wc -l In long-format output of ls
–l , named pipes are marked by the “p” symbol.
Sockets
A Unix socket (or Inter-process communication socket) is a special file which allows for
advanced inter-process communication. A Unix Socket is used in a client-server application
framework. In essence, it is a stream of data, very similar to network stream (and network
sockets), but all the transactions are local to the filesystem. In long-format output of ls -l,
Unix sockets are marked by “s” symbol.
Symbolic Link
Symbolic link is used for referencing some other file of the file system.Symbolic link is also
known as Soft link. It contains a text form of the path to the file it references. To an end
user, symbolic link will appear to have its own name, but when you try reading or writing
data to this file, it will instead reference these operations to the file it points to. If we delete
the soft link itself , the data file would still be there.If we delete the source file or move it to
a different location, symbolic file will not function properly. In long-format output of ls –l ,
Symbolic link are marked by the “l” symbol (that’s a lower case L).
Unix - File Management
In this chapter, we will discuss in detail about file management in Unix. All data in Unix is
organized into files. All files are organized into directories. These directories are organized
into a tree-like structure called the file system.
When you work with Unix, one way or another, you spend most of your time working with
files. This tutorial will help you understand how to create and remove files, copy and
rename them, create links to them, etc.
In Unix, there are three basic types of files −

Ordinary Files − An ordinary file is a file on the system that contains data, text, or
program instructions. In this tutorial, you look at working with ordinary files.

Directories − Directories store both special and ordinary files. For users familiar
with Windows or Mac OS, Unix directories are equivalent to folders.

Special Files − Some special files provide access to hardware such as hard drives,
CD-ROM drives, modems, and Ethernet adapters. Other special files are similar to
aliases or shortcuts and enable you to access a single file using different names.

Unix - File Permission


In this chapter, we will discuss in detail about file permission and access modes in Unix.
File ownership is an important component of Unix that provides a secure method for
storing files. Every file in Unix has the following attributes −

Owner permissions − The owner's permissions determine what actions the owner of
the file can perform on the file.

Group permissions − The group's permissions determine what actions a user, who is
a member of the group that a file belongs to, can perform on the file.

Other (world) permissions − The permissions for others indicate what action all
other users can perform on the file.

Login process:
Logging in to a Unix system requires two pieces of information: A username, and a
password. When you sit down for a Unix session, you are given a login prompt that
looks like this: login: Type your username at the login prompt, and press the return
key.

Managing disk quotas:

In order to keep from going over your quota, you must be sure to periodically clean
out old, unused, and unneeded files. Two commands are very helpful in bringing
your disk space back under control: The ls -al command shows you the contents of
your directory. The rm command removes any unnecessary files.
Hard link and a Symbolic link, any difference?

In order to find differences between these two types of links we first have to define them:

Symbolic Link:

The easiest way to understand what a symbolic link is in Linux is to compare it to the
“direct link” or “shortcut” in Windows. The file or directory is located at a single point on
the disk and the links are a pointer against it. Each symbolic link has its own inode number
which allows symbolic links to be made between different file systems.

To create links (both symbolic and hard links) we use the command ln. In this case, we will
create a symbolic link (parameter -s) from the test file:

$ ln -s test link-to-test

Hard Link:

The hard links are to associate two or more files sharing the same inode. This makes each
hard link an exact copy of the rest of the associated files, both data and permissions,
owner, etc. This also implies that when changes are made to one of the links or to the file,
these changes will also be made to the rest of the links.

Hard links cannot be made against directories or outside the file system itself.

We are going to create a hard link against the “test” file before and we will see that they
effectively share inode and that the data is synchronized between both:

$ ln test link-hard-test
$ ls -li

You might also like