Documente Academic
Documente Profesional
Documente Cultură
Introduction:
Duties of the Administrator, Administration tools, Overview of
permissions.
Processes: Process status, Killing processes, process priority.
Starting up and Shut down: Peripherals, Kernel loading, Console,
The scheduler, init and the inittab file, Run-levels, Run level scripts.
Keeping up to date
By Upgrading
Linux upgrades faster than Windows
Compatibility
Linux is Backward Compatible unlike Windows
• Proprietary vs. Open Source
• Windows is a Proprietary Technology
Applications will only work on Windows
• Linux – Open Source
System Administrator
When we type:
ls -l /usr/bin/top
We'll see:
-rwxr-xr-x 1 root root 68524 2011-12-19 07:18 /usr/bin/top
There are two ways to set permissions when using the chmod
command:
Symbolic mode:
testfile has permissions of -r--r--r--
U G O*
$ chmod g+x testfile ==> -r--r-xr--
$ chmod u+wx testfile ==> -rwxr-xr--
$ chmod ug-x testfile ==> -rw--r--r--
U=user, G=group, O=other (world)
chmod Command(Absolute Method)
Absolute mode:
We use octal (base eight) values represented like this:
Letter Permission Value
R read 4
W write 2
X execute 1
- none 0
For each column, User, Group or Other you can set values
from 0 to 7. Here is what each means:
0= --- 1= --x 2= -w- 3= -wx
4= r-- 5= r-x 6= rw- 7= rwx
chmod – Example (Absolute Method)
A new process is normally created when an existing process makes an exact copy of
itself in memory. The child process will have the same environment as its parent, but
only the process ID number is different.
There are two conventional ways used for creating a new process in Linux:
Using The System() Function – this method is relatively simple, however, it’s
inefficient and has significantly certain security risks.
Using fork() and exec() Function – this technique is a little advanced but offers
greater flexibility, speed, together with security.
System Calls
Daemons are (server) processes often initiated at runtime, that run continuously
when the system is up, waiting in background until a process require there services
e.g. Network processes .
Batch processes are queued into a spooler area, where they wait to be executed on
a FIFO basis. They are not associated with terminal rather they are submitted to a
queue, from which jobs are executed sequentially.
Interactive processes are initialized and controlled through a terminal session. They
may run either in foreground or background of terminal.
Process STAT
ps –a grep firefox
Kill The kill command can kill a process, given its process ID.
nice
renice
Using top..
26
Using ps
28
Using ps..
• ps –f :
– UID The user ID of the process’ owner.
– PPID The PID of the process’ parent process.
– C The amount of processor time utilized by the process.
– STIME The time that the process started
29
ps Command
"ps" Syntax
ps [options]
This is the basic "ps" command, with no flags and no arguments. It will list basic
information about your processes.
ps -e
This command lists every process that is currently running on the UNIX system.
ps -ef
This variation lists full information about every process that is currently running on
the UNIX system.
Killing Processes
kill
killall
xkill
Process priority is calculated from the nice number, and recent CPU usage of
the process.
nice
renice
A foreground job occupies the terminal which initialized it. It can be put in the
background, so that the terminal can accept new commands.
With the help of Nice command in Linux you can set process priority. If you give a
process a higher priority, then Kernel will allocate more cpu time to that process.
By default when a program is launched in Linux, it gets launched with the priority
of '0'. However you can change the priority of your programs by either of the
following methods.
You can launch a program with your required priority or you can also change the
priority of an already running process.
• In order to change the priority of an already running process you can use
"renice" command.
• renice command is very much similar to the nice command( interms of
options in priority), however it does differ slightly in terms of parameters.
You can give username,groupname etc in renice command as a parameter.
• renice -4 -p 3423 (this will set the priority of process id no 3423 to -4,
which will inturn increase its priority over others)
• renice 13 -p 3564 -u sarath (this will set the priority of the process id 3564
to 13, and all the process owned by user "sarath" to the priority of 13)
nice value is a user-space and priority PR is the process's actual priority that use
by Linux kernel. In linux system priorities are 0 to 139 in which 0 to 99 for real
time and 100 to 139 for users. nice value range is -20 to +19 where -20 is highest,
0 default and +19 is lowest. relation between nice value and priority is :
PR = 20 + NI
PR -- Priority The scheduling priority of the task. If you see 'rt' in this field, it
means the task is running under 'real time' scheduling priority.
1. Turn on Power
2. CPU jump to address of BIOS (Basic Input / Output System)
3. BIOS runs POST (Power-On Self Test)
4. POST performs System Integrity Checks
5. BIOS gives the control to boot loader
6. Loads and execute boot sector from MBR
(The MBR is a 512-byte sector, located in the first sector on
the disk (sector 1 of cylinder 0, head 0), MBR contains
Instructions for booting machine called Boot loader, along
with the partition table.
7. Boot loader program is detected and loaded into memory,.
8. Load OS (Kernel)
BIOS
Memory count
Search for the OS Boot device
Optical drive
USB device
Network device
HDD
HDD Boot Sequence
Loading and unloading of kernel modules is done with the help of programs like
insmod, and rmmod present in the initrd image.
Unmounts initrd image and frees up all the memory occupied by the disk
image.
Executes the system to boot into the run level as specified in /etc/inittab
id:runlevels:action:process
id - A unique sequence of 1-4 characters which identifies an entry in inittab.
runlevels - Lists the runlevels for which the specified action should be taken.
action - Describes which action should be taken.
process - Specifies the process to be executed
Example
1. id :3:initdefault:
2. si::sysinit:/etc/rc.d/rc.sysinit[System Initialization]
3. ca::ctrlaltdel:/sbin/shutdown -t3 -r now [Trap]
Valid actions
0-halt
1-Single user mode
2-Multiuser, without NFS (The same as 3, if you
don't have networking)
3-Full multiuser mode
4-unused
5-X11
6-Reboot
S or s – single user login
Runlevel scripts
0 /etc/rc.d/rc0.d
1 /etc/rc.d/rc1.d
2 /etc/rc.d/rc2.d
3 /etc/rc.d/rc3.d
4 /etc/rc.d/rc4.d
5 /etc/rc.d/rc5.d
Based on the selected runlevel, the init process executes startup scripts located in
subdirectories of the /etc/rc.d directory.
Scripts used for runlevels 0 to 6 are located in subdirectories /etc/rc.d/rc0.d through
/etc/rc.d/rc6.d, respectively.
There are s and k scripts in the /etc /rcx.d directories
init runs whatever it finds in /etc/rc.d/rc.local (regardless of run level). rc.local is rather
special in that it is executed every time that you change run levels.
NOTE: rc.local is not used in all the distros as for example Debian.
Managing User Accounts
Adding user
useradd abc
Changing password
passwd abc
Create user with different home directory
useradd -d /data/new abc
Create a User with Specific User ID
useradd -u 999 abc
(create user with specific UID and GID)
useradd -u 1000 -g 500 abc
Add user to many groups
useradd -G admins, webadmin, developers
grep abc /etc/passwd
/etc/passwd file
$1$ is MD5
$2a$ is Blowfish
$2y$ is Blowfish
$5$ is SHA-256
$6$ is SHA-512
Some Commands
• passwd
• pwck: The pwck command verifies the integrity of the users and
authentication information. It checks that all entries in /etc/passwd
and /etc/shadow have the proper format and contain valid data.
• grpck: grpck command verifies the integrity of the groups
information. It checks that all entries in /etc/groupand /etc/gshadow
• useradd: Add a group to the system.
• userdel
• usermod
• groupadd
• groupdel
• groupmod
• login
• vipw
Removing account
Remove login id from /etc/passwd & /etc/shadow file and delete home
directory
userdel –r <username>
or Use GUI to Delete the user
/etc/group contain four fields:
Group Name: Group Password: Group ID : Group Member
Group name should not be more then 8 characters
/etc/group
uname -arm
Linux 4.15.0-54-generic x86_64Copy
The output above shows that the Linux kernel is 64-bit and its version is 4.15.0-54, \
where:
•4 - Kernel Version.
•15 - Major Revision.
•0 - Minor Revision.
•54 - Patch number.
•generic - Distribution specific information.
hostnamectl
Static hostname: linuxize.localdomain
Icon name: computer-laptop
Chassis: laptop
Machine ID: af8ce1d394b844fea8c19ea5c6a9bd09
Boot ID: 15bc3ae7bde842f29c8d925044f232b9
Operating System: Ubuntu 18.04.2 LTS
Kernel: Linux 4.15.0-54-generic
Architecture: x86-64
The Relationship of shell functionality
Korn shell
Bourne
shell C shell
Common
core Common
core
CORE Shell Functionality
• Built-in commands
• Scripts
• Variables (local, environment)
• Redirection
• Wildcards
• Pipes
• Sequences (conditional, unconditional)
• Subshells
• Background processing
• Command substitution
What does the shell do?
block size is the size of chunks in which data will be spread. So if the block
size is 4K, then for a file of 15K it will take 4 blocks(because 4K*4 16), and
technically speaking you waste 1 K
Structure of Super Block
The segregation is majorly in the way these devices interact and perform I/O
with the operating system.
Device files allows program to communicate with the system’s hardware and
peripheral modules, for a particular device called device driver.`
Character Devices
Character Devices are devices where data is a stream of bytes i.e. the
input/output happens byte by byte. Therefore, the character device drivers
would be in a such a way to implement such kind of streamed data. The
interactive operations (often called the file operations) which would be most
vital to implement are:
– open()
– read()
– write()
– close()
Examples: A terminal, Keyboard, etc
.
Block Devices
Block Devices are devices, as the name suggests, deal with blocks of data.
Therefore, block device drivers are implemented to read/write block data and
also supports random access data. However, since data is to be handled in
blocks, therefore its implementation involves an extra intermediate buffer to
store data between reads and writes. It has block device operations such as
– open()
– release()
– direct_access()
– revalidate_disk()
etc.
Examples: A floppy, hard disks
Network devices
/etc/fstab fields
Example:-
<device> <mountpoint> <filesystemtype><options> <dump> <fsckorder>
/dev/hdc /mnt/cdrom iso9660 noauto,ro,user 0 0
Example:
• sync / async : All I/O to the file system should be done (a)synchronously.
• auto : The filesystem can be mounted automatically (at bootup, or when
mount is passed the -a option).
• noauto : The filesystem will NOT be automatically mounted at startup, or
when mount passed -a. You must explicitly mount the filesystem.
• dev / nodev : Permit any user to mount the filesystem.
• exec / noexec: Permit/Prevent the execution of binaries from the filesystem.
• suid / nosuid :Permit/Block the operation of suid, and sgid bits.
• ro :Mount read-only.
• rw :Mount read-write.
• User: Permit any user to mount the filesystem. This automatically implies
noexec, nosuid, nodev unless overridden.
• nouser:Only permit root to mount the filesystem. This is also a default setting.
• Defaults: Use default settings. Equivalent to rw, suid, dev, exec, auto, nouser,
async.
/etc/fstab fields
first field (/dev/hdc) is the physical device/remote filesystem which is to
be described.
second field (/mnt/cdrom) specifies the mount point where the filesystem
will be mounted.
third field (iso9660) is the type of filesystem on the device from the
first field.
fourth field (noauto,ro,user)is a (default) list of options which mount
should use when mounting the filesystem.
fifth field (0) is used by dump (a backup utility) to decide if
a filesystem should be backed up. If zero then
dump will ignore that filesystem.
sixth field (0) is used (the filesystem check utility) to determine
the order in which filesystems should be checked. If
zero then fsck won't check the filesystem.
MBR (Master Boot Record)
121