Bestant technologies
Linux task
Mentor : karthick
Delivered by:[Link]
1) Fdisk:-
How to add a disk?
fdisk also known as format disk
is a dialog-driven command in Linux used for creating
and manipulating disk partition table. It is used for the
view, create, delete, change, resize, copy and move
partitions on a hard drive using the dialog-driven
interface.
Step 1:
fdisk -l -> list out the disk in your machine .
Step 2:
fdisk /dev/sdb ->relocate the /dev/sdb
Enter m -> m for help
Enter n -> n for add a new partition
Enter p-> primary partition
Add memory what you want in size? Like +3G
Enter w->save and exit
Step 3:-
Partprobe /dev/sdb -> restart your kernel
Step 4:-
Mkfs.ext4 /dev/sdb1 -> To create the filesystem
Step 5:-
Mount /dev/sdb1 /app -> to mount your file
df-hT -> to check the filetype
Step 6:-
Vi /etc/fstab -> To edit the fstab (or) add the
partition in the /etc/fstab file.
Enter i -> to insert mode
Enter shift+g -> to move the last line of the
file
Then edit the /dev/sdb1 /app ext4 defaults 0 0
Enter esc & :wq -> save & exit the file
If you can restart (or) shutdown the machine the
memory allocation is available . if it is not saved on the
vi editor the file will not available when can you restart
(or) shutdown the machine
How to delete the disk?
Step 1:
Vi /etc/fstab -> go to the vi editor & delete the
added lines.
Enter shift+g->go to last line
Enter dd-> to delete the line
Enter :wq->save & exit the file
Step 3:
Umount /app-> to unmount the directory.
df-h->to check the file is deleted.
Step 4:
Fdisk /dev/sdb -> to move the sdb directory
Enter d->d for delete the partition
Enter p-> to check the partition
Enter w-> to exit the file
2) zip and gzip:
How to compress the file?
ZIP is a compression and file packaging
utility for Unix. Each file is stored in a single .zip {.zip-filename} file with
the extension .zip.
Syntax:
zip [options] [file_name.zip] [files_names]
`-d` Option in Zip command
Syntax:
zip -d [file_name.zip] [files_name]
Unzip:
unzip will list, test, or extract files from a ZIP
archive, commonly found on Unix systems. The
default behavior (with no options) is to extract into
the current directory (and sub-directories below it) all
files from the specified ZIP archive.
Syntax:
unzip [file_name.zip]
Gzip:
zip command compresses files. Each
single file is compressed into a single file. The
compressed file consists of a GNU zip header and
deflated data. If given a file as an argument, gzip
compresses the file, adds a “.gz” suffix, and deletes
the original file. With no arguments, gzip compresses
the standard input and writes the compressed file to
the standard output.
Syntax:
gzip file_name
How to decompress a gzip file in Linux?
The basic syntax of the gzip command for decompressing a file is as
follows:
gzip -d [Link]
How to ungzip file in linux?
Syntax:
gunzip [Link]
3)how to find the hidden file in linux?
The concept of hidden files is simple yet very important
in Linux. Hidden files are mainly used for storing
configuration files or user settings. Usually, system
services, scripts, or other programs use these files for
storing and reading configurations.
For example, the .bash_logout script executes
whenever you log out of your Bash sessions. Another
great example is the .gitignore file used by Git to
exclude certain files from being pushed to your remote
repository.
To show hidden files you must use the -a option. This
tells the ls command to list "all" files and folders
including hidden ones, i.e. those starting with a dot (.).
Syntax:
ls -la
4) Details about kernal:
The Linux kernel is the
main component of aThe Linux kernel is the main
component of a Linux operating system (OS) and is the
core interface between a computer’s hardware and its
processes. It communicates between the 2, managing
resources as efficiently as possible.
The kernel is so named because—like a seed inside a
hard shell—it exists within the OS and controls all the
major functions of the hardware, whether it’s a phone,
laptop, server, or any other kind of computer.
What the kernel does ?
The kernel has 4 jobs:
1. Memory management: Keep track of how much
memory is used to store what, and where
2. Process management: Determine which
processes can use the central processing unit
(CPU), when, and for how long
3. Device drivers: Act as mediator/interpreter
between the hardware and processes
4. System calls and security: Receive requests for
service from the processes
Where the kernel fits within the OS ?
To put the kernel in context, you can think of a Linux
machine as having 3 layers:
1. The hardware: The physical machine—the bottom
or base of the system, made up of memory (RAM)
and the processor or central processing unit (CPU),
as well as input/output (I/O) devices such as
storage, networking, and graphics. The CPU
performs computations and reads from, and writes
to, memory.
2. The Linux kernel: The core of the OS. (See? It’s
right in the middle.) It’s software residing in memory
that tells the CPU what to do.
3. User processes: These are the running programs
that the kernel manages. User processes are what
collectively make up user space. User processes
are also known as just processes. The kernel also
allows these processes and servers to
communicate with each other (known as inter-
process communication, or IPC).
5) how to find the cpu details?
Syntax:
lscpu
arch
Syntax:
uname -a
uname -r
uname
6) How to unzip file?
Syntax:
unzip file_name.zip file_name
Syntax:
Gunzip file_name
7)how to find release version?
Syntax:
Cat /etc/os-realease
Syntax:
grep '^VERSION' /etc/os-release
grep -E '^(VERSION|NAME)='
/etc/os-release
Syntax:
hostnamectl
Syntax:
Uname -r
8) what is the purpose of /proc and
/dev directories?
/proc:
The /proc directory is a virtual filesystem
that provides information about the system’s
processes and [Link]’s called a virtual
filesystem because it lives inside of the RAM and
consumes no physical storage. If the system is
shut down or restarted, the RAM is cleared and
files of the /proc directory are generated from
scratch.
/dev:
All devices connected to a Linux system
are represented by a device file inside the dev
directory. The directory’s name is short for
“devices”, and can be found attached to the root
filesystem.
There are many types of devices that can
connect to Linux system, but by far the most
encountered are:
● Character Devices
● Block Devices
/dev/sdb
9) how to delete one user?
Syntax:
Userdel -r username
Syntax:
Userdel -f username
10)how to unlock one user?
Syntax:
username -U username
11)how to copy one file in your home
path?
Syntax:
vi file_name ->to see the file text
cp file_name_1 file_name_2->copy the one file to
another file
[Link] root password
Step1: reboot your linux machine
Step2: press e & goto the last line of linux 16
Step3: type [Link] & press ctrl+x
Step4: enter mount -o [Link] /sysroot
Step5: chroot /sysroot
Step6: passwd
Step7: enter the new password
Step8: touch /.autorelabel
Step9: enter & enter & exit
[Link] about crontab?
The crontab is a list of
commands that you want to run on a regular schedule,
and also the name of the command used to manage
that list. Crontab stands for “cron table, ” because it
uses the job scheduler cron to execute tasks; cron itself
is named after “chronos, ” the Greek word for time. cron
is the system process which will automatically perform
tasks for you according to a set schedule. The schedule
is called the crontab, which is also the name of the
program used to edit that schedule.
* * * * *
| | | | |
Minutes hours days of month month day of week
[Link] to give special permissions?
Details?
Mostly special premmision is used for executable
1. Setuid -> user permission
|
suid->4-> it will be run privillage of root user
[Link] -> group permission
|
sgid->2
[Link] ->1
rws rws rws
| | |
Setuid setgid stickybit
s-> not properly setuid
1) Chmod 777 filename
777->full permission
2) Chmod 4777 filename
4777->setuid and full permission
3) chmod 2777 filename
2777->setgid and full permission
4)chmod 1777 filename
1777 -> stickbit & full permission
Stickybit used for security purpose . the root & owner
can remove files . other user can’t remove files.
5) chmod 0777 filename
0777 -> remove stickybit
6) chmod u+s filename
Set the setuid
7) chmod g+s filename
Set the setgid
8) chmod o+s filename
Set the stickybit
9)chmod u-s filename
Remove the setuid
10)chmod g-s filename
Remove the setgid
11)chmod o-s filename
Remove the stickybit
[Link] about systemd process?
Systemd is a system and service manager for Linux
operating systems. It is designed to be backwards
compatible with SysV init scripts, and provides a number
of features such as parallel startup of system services at
boot time, on-demand activation of daemons, or
dependency-based service control logic. In Red Hat
Enterprise Linux 7, systemd replaces Upstart as the
default init system.
[Link] is the purpose of /bin and
/boot directories?
1)/bin->Critical system programs and utilities are stored
in this directory. Software like a Firefox web browser are
stored in the /usr/bin directory. bin is shorthand for
binary or binaries.
2)/boot->This folder holds the files needed to boot (or
start up) the operating system. However, the
configuration files for booting up are in the /etc directory.
[Link] to create one file and
directory?
Create a file:
1) Touch [Link]
2) Vi [Link]
Create the directory:
Mkdir directoryname
[Link]@localhost ~}$ ---> Details
about every charactor functions?
Username -> is this which user you used
@localhost ->is this for which server you used
~ -> is this mentioned for your are in /home path
$ -> you are logged in the normal user
[Link] to add a user and set
password?
Add a user:
Sudo Useradd username
Set a password:
Sudo passwd username
[Link] to lock the one user?
Lock one user:
Sudo Usermod -L username
Password lock of one user:
Sudo passwd -l username
[Link] between cat > filename
and cat >> filename?
cat> cat>>
cat>[Link]-> file created with cat>>[Link]-> to add some
edit your content . press data of the file.
enter & ctrl+c (or) ctrl+d . the
file will be saved & we view
later using cat command
[Link] (Logical volume manager)
Downtime is not needed for this LVM
Step 1: fdisk -l ->listout the fdisk
Step 2: fdisk /dev/sdb -> goto fdisk sdb
Enter m -> for help
Enter n->add a new partition
Enter p-> primary
Enter +3G-> space you need like this
Enter w -> save & exit
Step 3: partprobe /dev/sdb ->restart your kernal
Step 4: mkfs.ext4 /dev/sdb1 ->make the filesystem
Step 5: mount /dev/sdb1 /app -> mount your storage
df -hT -> file types are shown
Step 6: vi /etc/fstab
/dev/sdb1 /app ext4 defaults 0 0 -> to edit
the file and save permanently
Step 7: fdisk /dev/sdb
Enter T -> change the partition’s id
Enter L -> list known partition type
Enter 8e-> linux lvm
Enter p -> partition
Enter w-> save & exit
Step 8: umount /app->unmount the app
Partprobe /dev/sdb ->restart the kernal
pvs->physical volume of display information
Pvcreate /dev/sdb1->create a physical volume
Step 9: vgs->volume group creator
vgcreate->create a volume group
Step 10: lvs->logical volume information
Lvcreate -n phy -L 3G MS0
Step 11: mkfs.ext4 /dev/MS0/phy
Mount /dev/MS0/phy /app
df -hT
Step 12: vi /etc/fstab
/dev/MS0-phy /app ext4 defaults 0 0
[Link] to disable one user
permenantly?
Delete the user permenantly:
Userdel -r username
Userdel -f username
[Link] about below vi editor
commands?
/ -> search the word (or) letter
A ->allow insert mode end of the line
o ->open a new line below and insert mode
O -> open a new line above and insert mode
w -> save
q ->exit
! -> forcefully
gg ->move cursor into first line
[Link] to create softlink and hardlink
Cat softlink -> view the softlink
Ln -s softlink filename->create the softlink file
Ln hardlink filename-> create the hardlink file
26.ssh_keygen password less
authentication
● Ssh -keygen ->defaults key will be created
● Ssh -keygen is secure shell
● Key based authentications
● Shell using ip_address
Types:
● RSA -> default key in linux
● DSA
● ECDSA
Ssh-keygen -t dsa
Steps:
1. Ssh-keygen
2. Enter enter enter
3. Cd .shh
4. Ssh-copy-id -i /home/raj/.ssh/id_rsa.pub
username@ip_address
5. Ssh username@ip_address
6. Now the key will be generated