2. A process means program in execution. It generally takes an input, processes
it and gives us the appropriate output. Check Introduction to Process
Management for more details about a process. There are basically 2 types of
processes.
1.Foreground processes: Such kind of processes are also known
as interactive processes. These are the processes which are to be executed or
initiated by the user or the programmer, they can not be initialized by system
services. Such processes take input from the user and return the output. While
these processes are running we can not directly initiate a new process from the
same terminal.
2.Background processes: Such kind of processes are also known as non
interactive processes. These are the processes that are to be executed or
initiated by the system itself or by users, though they can even be managed by
users. These processes have a unique PID or process if assigned to them and we
can initiate other processes within the same terminal from which they are
initiated.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
3. External Commands : Commands which aren’t built into the shell.
When an external command has to be executed, the shell looks for its
path given in the PATH variable, and also a new process has to be
spawned and the command gets executed. They are usually located in
/bin or /usr/bin. For example, when you execute the “cat” command,
which usually is at /usr/bin, the executable /usr/bin/cat gets executed.
Examples: ls, cat etc.
The type command: The type command is used to describe how its
argument would be translated if used as commands. It is also used to
find out whether it is built-in or external binary file.
Syntax: type [Options] command names
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
4. Example:
Options:
-a : This option is used to find out whether it is an alias, keyword or a function
and it also displays the path of an executable, if available.
Example: type -a pwd
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
5. -t : This option will display a single word as an output.
alias – if command is a shell alias
keyword – if command is a shell reserved word
builtin – if command is a shell builtin
function – if command is a shell function
file – if command is a disk file
Example:
type -t pwd type -t cp type -t ls type -t while
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
6. -p : This option displays the name of the disk file which would be
executed by the shell. It will return nothing if the command is not a disk
file.
Example: type -p dash
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
7. The man command: man command in Linux is used to display the user
manual of any command that we can run on the terminal. It provides a detailed
view of the command which includes NAME, SYNOPSIS, DESCRIPTION,
OPTIONS, EXIT STATUS, RETURN VALUES, ERRORS, FILES, VERSIONS,
EXAMPLES, AUTHORS and SEE ALSO.
Every manual is divided into the following sections:
Executable programs or shell commands
System calls (functions provided by the kernel)
Library calls (functions within program libraries
Games
Special files (usually found in /dev)
File formats and conventions eg /etc/passwd
Miscellaneous (including macro packages and conventions), e.g. groff(7)
System administration commands (usually only for root)
Kernel routines [Non standard]
Syntax : $man [OPTION]... [COMMAND NAME]...
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
8. Options and Examples:
1.No Option: It displays the whole manual of the command.
Syntax : $ man [COMMAND NAME]
Example: $ man printf
Output:
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
9. In this example, manual pages of the command ‘printf‘ are simply returned.
2. Section-num: Since a manual is divided into multiple sections so this option is
used to display only a specific section of a manual.
Syntax : $ man [SECTION-NUM] [COMMAND NAME]
Example: $ man 2 intro
Output:
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
10. In this example, the manual pages of command ‘intro‘ are returned which lies in
the section 2.
3. -f option: One may not be able to remember the sections in which a command
is present. So this option gives the section in which the given command is present.
Syntax: $ man -f [COMMAND NAME]
Example: $ man -f ls
Output:
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
11. In this example, the command ‘ls‘ is returned with its section number.
4. -a option: This option helps us to display all the available intro manual pages
in succession.
Syntax: $ man -a [COMMAND NAME]
Example: $ man -a intro
Output:
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
13. In this example you can move through the manual pages(sections) i.e either
reading(by pressing Enter) or skipping(by pressing ctrl+D) or exiting(by pressing
ctrl+C).
5. -k option: This option searches the given command as a regular expression in
all the manuals and it returns the manual pages with the section number in which
it is found.
Syntax: $ man -k [COMMAND NAME]
Example: $ man -k cd
Output:
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
14. The command ‘cd‘ is searched in all the manual pages by considering it as a
regular expression.
6. -w option: This option returns the location in which the manual page of a
given command is present.
Syntax: $ man -w [COMMAND NAME]
Example: $ man -w ls
Output:
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
15. The location of command ‘ls‘ is returned.
7. -I option: It considers the command as case sensitive.
Syntax: $ man -I [COMMAND NAME]
Example: $ man -I printf
Output:
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
17. The command ‘printf‘ is taken as case-sensitive i.e ‘printf‘ returns the manual
pages but ‘Printf‘ gives error.
User terminal:
A Unix Terminal is really just a way to pump characters into a /dev/tty device
and read characters and control characters from the same device. A terminal by
itself does not offer
To be able to parse user input, interpret that input as commands to run and
display results, we need a Unix Shell. The Shell manages things like prompt,
where you write your commands much functionality.
A terminal (also called TeleTYpewriter (_tty_)) is an interface to the
underlying OS, which is connected to a server. Some terminals are
provided by the kernel on behalf of a hardware device, with the input coming
from the keyboard and the output going to a text mode screen.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
18. The root login:-Root is the superuser account in Unix and Linux. It is a user
account for administrative purposes, and typically has the highest access rights on
the system.
Usually, the root user account is called root. However, in Unix and Linux, any
account with user id 0 is a root account, regardless of the name. It is fairly
common for certain system administrators to have their own root accounts on a
system, with their own passwords.
Root is the superuser account in Unix and Linux. It is a user account for
administrative purposes, and typically has the highest access rights on the system.
Usually, the root user account is called root . However, in Unix and Linux, any
account with user id 0 is a root account, regardless of the name.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
19. The root is the super-user account on Linux-based operating systems. The root
user has all the rights that are necessary to perform administrative tasks or access
some files, execute privileged commands, and much more. The root user is also
referred to as a superuser or root.
In Linux, you can run privileged commands using the sudo keyword. However,
sometimes it becomes a tedious act when you are doing administrative tasks and
each command requires root privileges. To get rid of such a situation, become a
root user and then execute commands.
su command: The su command allows you to switch the user to someone else
by providing its username. However, if the name is not specified,
the su command would allow you to execute the commands with root privileges.
The su command allows you to run a shell as another user.
Syntax : su <username>
Example : su jtp
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
20. user account is changed from sssit to jtp
su to root
You can change the user to root when you know the root password.
Syntax : su root
su as root
The root user can become any existing user without knowing that
user's password. Otherwise, password is needed.
Example : su - sssit
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
21. Look at the above snapshot, it is asking for password while switching
from user jtp to sssit.
Now let's look at the following example.
Example : su - jtp
Look at the above snapshot, we are at user root. While switching from
root to jtp it didn't ask for password and we're successfully arrived at
user jtp.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
22. Authentication with /etc/passwd and /etc/shadow
In older Linux systems, user information, including passwords and usernames,
are kept in a system file called /etc/passwd. This plaintext database is used to
keep track of every user on the Linux system. The file is owned by the root and
can only be modified by root or users with sudo privileges, although it is
readable by all system users.
Each user's password is stored in an encrypted form within the /etc/passwd
file. These credentials are hashed using a one-way hash function so they cannot
be decrypted. So, user authentication takes place by comparing the contents of
the /etc/passwd file to the user's encrypted password upon logging in -- after
the password is rehashed with the key or salt.
If there is a mismatch, the user cannot access the system. However, the reuse of
passwords -- a common problem among users -- and the increasing use
of rainbow tables by threat actors to crack password hashes and gain entry into
Linux systems have made this old system insecure.
The /etc/shadow file provides an enhanced authentication mechanism for
Linux systems by tightening access at the account level. This text file stores
actual passwords in hashed format, along with additional information related
to these passwords.
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
23. Commands to add, modify and delete users.
Add a user in Linux:
To add users, run the useradd command, like so:
sudo useradd -m <name of the user>
For example, if you want to add the user named john, then the command will be
like:
sudo useradd -m john
By default, useradd creates a user without creating a home directory. So, to
make useradd create a home folder, we’ve used the -m switch.
If the command is successful, it won’t have any output, like so:
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
24. Behind the scenes, it automatically creates the user john by assigning a unique
user ID for the user, and adding the user’s details to the /etc/passwd file. It also
creates a home directory for the user under /home (so the full path
is /home/john).
At this point, the user has been created, but they don’t have a password and
can’t log in. So, to assign a password to the newly created user, run
the passwd command like so:
sudo passwd <username>
The command will ask for the new password, and ask you to confirm it:
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune
25. This command adds the user’s password in /etc/shadow in an encrypted
format. After running this command, the new user should be able to login as
usual.
You can view the new user’s ID by using id -u <username>. In our
case, john was given an ID of 1001:
Mrs.Harsha V Patil, MIT ACSC Alandi , Pune