Linux
Linux
Linux
AIM:
File system hierarchy in a common Linux distribution, file and
device permissions, study of system configuration files in /etc,
familiarizing log files for system events, user activity, network
events.
Its current version is 3.0 released on June 3rd 2015 and is maintained
by Free Standards Group. In Unix like operating system everything is
considered as a file.
Only Linux distributions follow the FHS and that too partially.
Because every distro have their own policy due to which you may
notice some differences in the directory tree structure of different
distros.
If you want to find out information about your system's FHS, enter
the command man hier. It will display directory structure of your
system.
Linux Directories
We have categorize the directories according to the type of file as given below:
Binary directories Contains binary or compiled source code files, eg, /bin, /sbin, e
Configuration directories Contains configuration files of the system, eg, /etc, /boot.
Memory directories Stores device files which doesn't take up actual hard disk spa
/sys.
Usr (Unix System Contains sharable, read only data, eg, /usr/bin, /usr/lib, etc.
Resources)
var (variable directory) Contains larger size data, eg, /var/log, /var/cache, etc.
Non-standard directories Directories which do not come under standard FHS, eg, lost+fo
o /bin
o /sbin
o /lib
o /opt
/bin
/sbin
The '/sbin' directory also contains executable files, but unlike '/bin' it
only contains system binaries which require root privilege to perform
certain tasks and are helpful for system maintenance purpose. e.g.
fsck, root, init, ifconfig, etc.
Example:
1. ls /sbin
/lib
The '/lib' directory contains shared libraries which are often used by
the '/bin' and '/sbin' directories. It also contains kernel module. These
filenames are identable as ld* or lib*.so.*. For example, ld-linux.so.2
and libfuse.so.2.8.6
Example:
1. ls /lib
/opt
The term 'opt' is short for optional. Its main purpose is to store
optional application software packages. Add-on applications from
individual vendors should be installed in '/opt'. And so in some
systems '/opt' is empty as they may not have any add-on application.
o /boot
o /etc
/boot
The '/boot' directory contains boot loader files which are essential to
boot the system. In other words, they only contain files which are
needed for a basic Linux system to get up and going.
Example:
1. ls /boot
Look at the above snapshot, command "ls /boot" displays the list of
'/boot' directory.
/etc
All the machine related configurtion files are kept in '/etc'. Almost
everything related to the configuration of your system is placed here.
It also contain startup and shutdown shell script which is used to start
and stop a program. All the files are static and text based and no
binary files can be placed in this directory.
o /home
o /root
o /srv
o /media
o /mnt
o /tmp
/home
The '/home' directory stores users personnel files. After the '/home'
there is a directory which is generally named at the user's name like
we have '/home/sssit'. Inside this directory we have our sub-
directories like Desktop, Downloads, Documents, pictures, etc.
Example:
/root
/srv
The term 'srv' is short for service. The '/srv' directory contains server
specific data for services provided by the system like www, cvs,
rysync, ftp, etc.
/media
/mnt
The term 'mnt' stands for mount. The '/mnt' directory should be
empty and sysadmins can only mount temporary filesystems.
/tmp
o /dev
o /proc
o /sys
/dev
The term 'dev' is short for device. As you know in Linux operating
system everything is a file. It appears to be an ordinary file but
doesn't take up disk space. Files which are used to represent and
access devices are stored here including terminal devices like usb. All
the files stored in '/dev' are not related to real devices, some are
related to virtual devices also.
/proc
The term 'proc' is short for process. Same as '/dev', '/proc' also
doesn't take up disk space. It contains process information. It is a
pseudo filesystem that contains information about running
processes. It also works as virtual filesystem containing text
information about system resources.
6.4M
155
How to find Nth Highest Salary in SQL
o /proc conversation with the kernel: The '/proc' displays view of
the kernel, what the kernel manages and it is a means to directly
communicate with the kernel.
Example:
1. ls /proc
The '/proc' has some file properties like date, which keeps on
updating as shown in the below snapshot.
Also most of the files in '/proc' are of 0 bytes yet they contain a lot
of data. Most of the files are readable only, some require root
privileges and some are writable.
Example:
1. cat /proc/interrupts
/sys
1. Ownership
2. Permission
A user is the owner of the file. By default, the person who created a file
becomes its owner. Hence, a user is also sometimes called an owner
Group
A user- group can contain multiple users. All users belonging to a group
will have the same Linux group permissions access to the file. Suppose
you have a project where a number of people require access to a file.
Instead of manually assigning permissions to each user, you could add all
users to a group, and assign group permission to file such that only this
group members and no one else can read or modify the files.
Other
Any other user who has access to a file. This person has neither created
the file, nor he belongs to a usergroup who could own the file.
Practically, it means everybody else. Hence, when you set the permission
for others, it is also referred as set permissions for the world.
Now, the big question arises how does Linux distinguish between these
three user types so that a user 'A' cannot affect a file which contains
some other user 'B's' vital information/data. It is like you do not want
your colleague, who works on your Linux computer, to view your images.
This is where Permissions set in, and they define user behavior.
Permissions
• Read: This permission give you the authority to open and read a
file. Read permission on a directory gives you the ability to lists its
content.
• Write: The write permission gives you the authority to modify the
contents of a file. The write permission on a directory gives you the
authority to add, remove and rename files stored in the directory.
Consider a scenario where you have to write permission on file but
do not have write permission on the directory where the file is
stored. You will be able to modify the file contents. But you will not
be able to rename, move or remove the file from the directory.
• Execute: In Windows, an executable program usually has an
extension ".exe" and which you can easily run. In Unix/Linux, you
cannot run a program unless the execute permission is set. If the
execute permission is not set, you might still be able to see/modify
the program code(provided read & write permissions are set), but
not run it.
Here, we have highlighted '-rw-rw-r--'and this weird looking code is the one
that tells us about the Unix permissions given to the owner, user group and
the world.
r = read permission
w = write permission
x = execute permission
- = no permission
The first part of the code is 'rw-'. This suggests that the owner 'Home' can:
By design, many Linux distributions like Fedora, CentOS, Ubuntu, etc. will
add users to a group of the same group name as the user name. Thus, a user
'tom' is added to a group named 'tom'.
The second part is 'rw-'. It for the user group 'Home' and group-members
can:
The third part is for the world which means any user. It says 'r--'. This
means the user can only:
We can use the 'chmod' command which stands for 'change mode'. Using
the command, we can set permissions (read, write, execute) on a
file/directory for the owner, group and the world. Syntax:
1. Absolute mode
2. Symbolic mode
Absolute(Numeric) Mode
In this mode, file permissions are not represented as characters but a three-
digit octal number.
This is how you can change user permissions in Linux on file by assigning an
absolute number.
Symbolic Mode
In the Absolute mode, you change permissions for all 3 owners. In the
symbolic mode, you can modify permissions of a specific owner. It makes
use of mathematical symbols to modify the Unix file permissions.
In case you want to change the user as well as group for a file or directory use
the command
In case you want to change the user as well as group for a file or directory
use the command
The term 'opt' is short for optional. Its main purpose is to store optional
application software packages. Add-on applications from individual
vendors should be installed in '/opt'. And so in some systems '/opt'
is empty as they may not have any add-on application.
Most of the configuration files in the Red Hat Linux system are in
the /etc directory unless otherwise specified. The configuration
files can be broadly classified into the following categories:
Access files
Tells the network domain server how to look up hostnames.
(Normally /etc/hosts, then name server; it can be changed
/etc/host.conf through netconf.)
Contains a list of known hosts (in the local network). Can be
used if the IP of the system is not dynamically generated. For
simple hostname resolution (to dotted notation),
/etc/hosts.conf normally tells the resolver to look here
/etc/hosts before asking the network nameserver, DNS or NIS.
/etc/hosts.allowMan page same as hosts_access. Read by tcpd at least.
/etc/hosts.deny Man page same as hosts_access. Read by tcpd at least.
Log Files
Log files are the records that Linux stores for administrators to keep track
and monitor important events about the server, kernel, services, and
applications running on it. In this post, we’ll go over the top Linux log files
server administrators should monitor.
What are Linux log files
Log files are a set of records that Linux maintains for the
administrators to keep track of important events. They
contain messages about the server, including the kernel,
services and applications running on it.
• Application Logs
• Event Logs
• Service Logs
• System Logs
/var/log/messages
/var/log/auth.log
Suspect that there might have been a security breach in your server?
Notice a suspicious javascript file where it shouldn’t be? If so, then
find this log file asap!
/var/log/secure
RedHat and CentOS based systems use this log file instead of
/var/log/auth.log.
/var/log/boot.log
• The system initialization script, /etc/init.d/bootmisc.sh, sends
all bootup messages to this log file
• This is the repository of booting related information and
messages logged during system startup process.
How can I use these logs?:
/var/log/dmesg
dmesg
• This log file contains Kernel ring buffer messages.
• Information related to hardware devices and their drivers are
logged here.
• As the kernel detects physical hardware devices associated with
the server during the booting process, it captures the device
status, hardware errors and other generic messages.
How can I use these logs?:
/var/log/faillog
It can be a useful log file to find out any attempted security breaches
involving username/password hacking and brute-force attacks.
/var/log/
cron
This log file records information on cron jobs.
• Whenever a cron job runs, this log file records all relevant
information including successful execution and error messages
in case of failures.
• If you’re having problems with your scheduled cron, you need to
check out this log file.
/var/log/yum.log
It contains the information that is logged when a new package is
installed using the yum command.
/var/log/
maillog or /var/log/mail.log
All mail server related logs are stored here.
/var/log/mysqld.log or /var/log/mysql.log