Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Enterprise Linux
Deepesh Sinnya
M.E Computer NCIT
RHCE,RHCSA
Cypher Technology P. Ltd.
dsinnya@gmail.com, deepesh@cyphertechnepal.com
So what is Linux?
It’s an operating system or OS.
Terminal can be remotely accessed via ssh with suitable tool. (putty, other bash
shell)
The Basics
Start with some of the informative commands then move onto navigational
commands.
The Basics
Command Details
who This will display information about who is logged on, both
yourself and others.
whoami This will display information about the current user i.e. You!
ls ls is short hand for LiSt. It will display all the visible files
within the directory that you are currently in. The files will
be listed alphabetically by default but this can be altered with
flags.
pwd This will Print the Working Directory. A fancy way of asking
the computer to display information about where you are and
what directory you are currently working in.
apropos Keyword This command followed by a keyword will provide you with
information on commands that are related to that keyword.
man Command This will provide you with the manual for the given command.
The Basics
Using these commands you can gather information about the digital world around
you, using flags will give you even more control.
We will place the flags behind the ls command for demonstrative purposes
The Basics
Flag Details
ls -a LiSt All – This will list all of the files in the directory including the
hidden dot files.
ls -l LiSt Long – This will list all the files and/or subdirectories with
detailed information such as file size, date modified etc.
ls -t LiSt Time – This will sort the list into a chronological order based on
modification time.
ls -tu This list will list them chronologically based on the last access date.
ls -R This list will include the content of subdirectories.
ls –S LiSt Size – This list will be based on the size order.
ls –h LiSt Human – this will make the list human readable format for
example the size would be 1.0MB instead of 1004638
ls -r LiSt Reversed – This will list the files in a reverse alphabetical order.
The Basics
The commands for getting around the directories and file structures are really
simple.
Inverted tree like design with the root directory at the top, the user home
directory and other essential folders below that, and the general
directories/subdirectories below this.
The Basics
The Basics
Command Details
cd .. Change Directory - to one level up the tree.
cd ~ Change Directory - to the home directory
mkdir Make DIRectory – this creates a new directory within the
current working directory
rmdir Directory ReMove DIRectory – This will remove the named directory,
It must be within the current working directory
rm –r Directory ReMove – the r flag on this command will along with its
contents
rm –i Directory ReMove – the i flag on this command will make it so there
is user interaction, i.e. the computer will ask for
confirmation
rm –ir Directory ReMove – the combination ir will remove all files within
the directory and ask for confirmation for each file within
it.
mv filename new_filename MoVe – This will move the file to a new location
cp filename new_filename CoPy – This will make a copy of the file under the
specified name.
SSH (Secure Shell):
SSH provides a secure channel for data transmission
Provides a secure pipe to open up a command interpreter
Latest version of SSH –SSH3
Accessing Linux terminal via SSH
SSH Supports secure remote logins, secure remote command execution, secure
file transfers
Default SSH port ????
Has a client server architecture – SSH server program and client program.
Make sure the SSH service is up and running on the server we are trying to access.
Accessing Linux terminal via SSH
Then access the remote server terminal using SSH via (bash shell or terminal
emulator like putty.)
Accessing Linux terminal via SSH
Following example shows us how to access remote terminal via bash shell.
Using Grep Utility:
The ‘grep’ command searches for a pattern in a file (or standard input). It
supports regular expressions. It returns a line if it matches the pattern in
that line. So, if we wish to find the lines containing the word ‘nologin’, we
use ‘grep’ as follows
More examples:
$grep bash /etc/passwd -> greps out user with bash shell
$grep ^# /etc/profile -> shows comment line only in the file profile
Using find Utility:
The find command in UNIX/LINUX is a command line utility for walking a file
hierarchy. It can be used to find files and directories and perform subsequent
operations on them.
It supports searching by file and directories that matches given criteria like
name,size,modification date, owner and permissions. By using the ‘-exec’ other
UNIX commands can be executed on files or folders found.
Syntax
find <path> [option] <Argument>
Examples:
1. Find all the files inside /etc directories that have been modified with in last
7 days:
# find /etc –mtime -7 -> -mtime option is from modification time search
2. Find all the files inside the whole system that have .conf extension.
# find / -name *.conf
Using find Utility:
3. Find all the files inside /var/log directory that are larger than 10 KB
# find /var/log –size +10KB
Example:
Create a compressed archive of /etc/ as /root/etc.tar.gz
# tar -zcvf /root/etc.tar.gz /etc ->using gzip
gzip compress verbose file
extraction
Managing Services:
To view status of a service in RHEL 7/ CENTOS 7:
# systemctl status <service name>
To start a service in RHEL 7/ CENTOS 7:
# systemctl start <service name>
To stop a service in RHEL 7/ CENTOS 7:
# systemctl stop <service name>
To restart a service in RHEL 7/ CENTOS 7:
# systemctl restart <service name>
To enable start a service after system restart in RHEL 7/ CENTOS 7:
# systemctl enable <service name>
To disable start a service after system restart in RHEL 7/ CENTOS 7:
# systemctl disable <service name>
Managing Services:
In CENTOS 6 and older version
#service <service name> start /restart / stop
Group
The name of the group that has permissions in addition to the file's owner.
Owner
The name of the user who owns the file.
File Permissions
The first character is the type of file. A "-" indicates a regular
(ordinary) file. A "d” indicate a directory. Second set of 3 characters
represent the read, write, and execution rights of the file's owner. Next 3
represent the rights of the file's group, and the final 3 represent the rights
granted to everybody else.
User, Group and Permission:
Example for assigning permission to file/directory:
# chmod u=rwx, g=rx, o=r file1
same thing can be done using following command:
#chmod 754 file1
Why is value 754?
7=r+w+x=4+2+1
5=r+x=4+1
4=r=4
Changing ownership:
#chown dsinnya:root file1 ->changes owner of file to dsinnya and assings it to
group root.
file owner group
User, Group and Permission:
Cat /etc/passed ->user’s database file
Format:
username : x : UID :GID:<comment>:<Home Directory>:<shell>
Here BOOTPROTO=static to
configure static IP
Also following are our added
static parameter
ADDR0=192.168.174.132
NETMASK0=255.255.255.0
GATEWAY0=192.168.174.2
DNS1=8.8.8.8
Package management:
Yellow Dog Updater, Modified (YUM):
The YUM tool was developed for the Yellow Dog Linux system as a replacement for
the Yellow Dog Updater (YUP). RedHat found the YUM tool to be a valuable addition
to their systems. Today, YUM is the default package and repository management
tool for a number of operating systems.
You can use the following commands to interact with YUM:
#yum install package-name(s) - Installs the specified package(s) along with any
required dependencies.
# yum remove package-name(s) - Removes the specified package(s) from your
system.
# yum search search-pattern - Searches the list of package names and descriptions
for packages that match the search pattern and provides a list of package names,
with architectures and a brief description of the package contents. Note that
regular expression searches are not permitted.
#yum deplist package-name(s) - Lists all of the libraries and modules that the named
package depends on, along with the names of the packages (including versions) that
provide those dependencies.
Package management:
#yum check-update - Refreshes the local cache of the yum database so that
dependency information and the latest packages are always up to date.
#yum info package-name(s) - The results of the info command provides the name,
description of the package, as well as a link to the upstream home page for the
software, release versions and the installed size of the software.
#yum reinstall package-name(s) - Erases and then downloads a new copy of the
package file and re-installs the software on your system.
#yum update optional-package-name(s) - Downloads and installs all updates
including bug fixes, security releases, and upgrades, as provided by the distributors
of your operating system. Note that you can specify package names with the
update command.
#yum upgrade - Upgrades all packages installed in your system to the latest
release.
Package management:
Installing Web server:
#yum –y install httpd
#systemctl start httpd
#systemctl enable httpd
#firewall-cmd –-permanent –-add-service=http
#firewall-cmd –-permanent –-add-service=https
#firewall-cmd –-reload
#firewall-cmd –-list-all
YUM is simply front-ends to a lower-level tool called RPM, similar to apt-get’s relationship
with dpkg in case of Ubuntu. You will likely not need to interact with RPM very often, but
there are a few commands that you may find useful.
The following commands should be run as root. The flags are expanded here, but the
abbreviated syntax is also included:
# rpm -ivh filename.rpm - Installs an rpm from the file. rpm is also capable of installing RPM
files from http and ftp sources as well as local files.
# rpm --erase package-name(s) or # rpm -e - Removes the given package. Usually will not
complete if package-name matches more than one package, but will remove more than one
match if used with the --allmatches flag.
# rpm --query --all or # rpm -qa - lists the name of all packages currently installed.