0% found this document useful (0 votes)
18 views

Linux Notes

Uploaded by

laharisravs6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Linux Notes

Uploaded by

laharisravs6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 13

AWS Account Creation

Launch Instance
How to connect an machine via openssh tool and putty?
==========================================================================
Operating system - Linux OS
==========================================================================
Operating system : Operating system is software which we used for launching/running
any application.

* Microsoft Windows : XP/7/10/11 -> Personal use OS (Individual machine/user -


configuration/resources are minimal
-> GUI and CLI
2008/2012/2016 -> Server Operating system - Live system
( configuration is high)
-> CLI
* Linux : GUI and CLI(recommended)
Redhat - RHEL - 3.x/4.x/5.x/6.x/7.x(stable)/8.x(stable)/9.x(latest)
Debian - Ubuntu - 14.x/16.x/18.x(stable)/20.x(stable)/22.x(latest)
Amazon - Amazon AMI
Centos - 5/6/7/8/9
kali linux - 5/6/7/8
Mint - 5/6/7/8
Fedora -5/6/7/8
===================================================================================
===============
Datacenter: Datacenter is secure location/building/room where you keep servers,
firewall devices, routers, switches,AC's, coolers etc.

Servers - Server is a Machine which contains software & hardware.

Physical machine: Something you can touch or access directly


Machine which has its own resources(cpu, os, ram, harddisk,
softwares)

Virtual Machine : Something which is accessed over internet/network


Machine which is accessing resources virutally.

Machine - (Server/physical machine(server /virutal machine(server) (VM)/ linux


box/windows box)
===================================================================================
================
Cloud : Cloud is service providers providing services over internet which can
accessed via browser.

Cloud service providers : AWS/AZURE/GCP/IBM/Digital Ocean/Rackspace etc


Cloud MOdel : IAAS, PAAS, SAAS
Cloud Types : public/private/hybid

Why Cloud?

eg:
Company : TCS (Own Datacenter)
Clients : Manage website and provide infrastructure support
Contract : Client says IAAS - Sale on website ( 3 months)
* Own Building / Rent building
* purchase Hardware, OS, firewall devices, routers, switches
* 100 machines -> 500 machines
* AC's and Coolers
* Labor ( cleaning staff, Hardware engineer, electricans)
* AMC, servicing, warranty
* Maintainence ( security, cameras etc)
===================================================================================
=======
Cloud : We will provide server over internet and pay as much as you use.
* No own building/ Rent Building
* No Hardware maintainence
* No software,firewall, routers, switches
* No Ac's , No cooler
* No Maintainence (labor,security, cameras)
* Skilled Employee who can work on Cloud services
* Basic Internet connection and laptop ( Browser)
===================================================================================
======================
Basic Linux Command:
===================================================================================
======================
Naming convention:
1. Machine - server
2. Folder - directory
3. Location - path
4. Software - package

=====================================
man pages - help documentation

ls --help
man <command_name>
===================================================================================
===============================================================
1. Check which operating system version/Name
cat /etc/redhat-release -> OS name & version
cat /etc/os-release -> OS name & version

[ec2-user@ip-172-31-15-106 ~]$ cat /etc/redhat-release


Red Hat Enterprise Linux release 9.0 (Plow)
[ec2-user@ip-172-31-15-106 ~]$
===================================================================================
==========================
2. How much time machine is up & running and load on machine?
uptime
[ec2-user@ip-172-31-15-106 ~]$ uptime
04:03:25 up 6 min, 1 user, load average: 0.00, 0.02, 0.00
[ec2-user@ip-172-31-15-106 ~]$
===================================================================================
==========================

3. How to check date and time in machine?


date
===================================================================================
==========
4. list files and directory (folder)?
ls -> listing

ls -lrt -> detailed listing

-l long listing
-r recursive
-t formatting

[ec2-user@ip-172-31-15-106 ~]$ ls -lrt


total 0
-rw-r--r--. 1 ec2-user ec2-user 0 Apr 3 04:05 file_name
drwxr-xr-x. 2 ec2-user ec2-user 6 Apr 3 04:05 dir_1
[ec2-user@ip-172-31-15-106 ~]$ ls
dir_1 file_name
[ec2-user@ip-172-31-15-106 ~]$

File:

- rw-r--r--. 1 ec2-user ec2-user 0 Apr 3


04:05 file.txt
Regular file Permissions link username group_name size date
& time filename

Directory:

d rwxr-xr-x. 2 ec2-user ec2-user 6 Apr 3 04:05


dir_1
Directory Permissions link user group size date & time
directory_name
KB - 1024000 KB
MB - 1024 MB
GB - 1GB

===================================================================================
5. display output of files

cat /path/of/file

eg : cat file.txt

[ec2-user@ip-172-31-15-106 ~]$ cat > devops-work


Hello Devops
[ec2-user@ip-172-31-15-106 ~]$ ls -lrt
total 4
-rw-r--r--. 1 ec2-user ec2-user 0 Apr 3 04:05 file_name
drwxr-xr-x. 2 ec2-user ec2-user 6 Apr 3 04:05 dir_1
-rw-r--r--. 1 ec2-user ec2-user 13 Apr 3 04:13 devops-work
[ec2-user@ip-172-31-15-106 ~]$ cat devops-work '
> ^C
[ec2-user@ip-172-31-15-106 ~]$ cat devops-work
Hello Devops
[ec2-user@ip-172-31-15-106 ~]$

===================================================================================
=
6. Directory creation

mkdir -> make directory

eg: mkdir directory_name

eg : mkdir test
cd test -> mkdir test1
cd test1 -> mkdir test2
cd test2 -> mkdir test3

eg : mkdir -p test-sample/test111/test222/test333
====================================================================

7. Change directory: -> switch between directories


*cd directory_name -> switching forward into directory
* cd .. -> go one directory back ( switching back to parent directory)
- cd ../../../
* cd -> home directory of user
===================================================================
8. Remove directory

rmdir directory_name -> empty directory


rm -rf dir_name -> delete all files/directories recursivly

rm -rf *

-r recursive
-f force
=====================================================================
9. Create file

touch file_name -> ēmpty file

touch -> timestamp


==========================================================================
text Editors : vi/vim/nano
==========================================================================
vi file_name -> create and open the file

readonly mode : cannot type anything


insert mode : i -> here we can type anything ( write mode)
readonly mode : esc
:w -> save
:q -> quit
:wq -> save and quit

dd - delete a line
u - undo changes
x - single character delete

===================================================================================
========
10. Delete files

rm file_name
rm -i file_name -> -i -> confirmation (yes/no)
rm -f file_name -> forcefully
rm -rf file_names
===================================================================================
======
11. Present working directory
[ec2-user@ip-172-31-15-106 test]$ pwd
/home/ec2-user/test
[ec2-user@ip-172-31-15-106 test]$
=========================================================
12. wget : Download any packages/files
wget https://archives.jenkins-ci.org/redhat-stable/jenkins-2.361.2-1.1.noarch.rpm
===================================================================================
===================
13. which and whereis
eg which httpd
whereis httpd
===================================================================================
===================
User Management:
===================================================================================
===================
3 Types of user in linux:
===================================================================================
====================
Super/admin User - root - id(0) - /root - group(root) - shell -> /bin/bash
System User - ping, daemon etc - id(1 - 999) - /ping - group(ping) - shell -
/sbin/nologin
Regular/Normal User - sonarqube, john, smith etc - id(1000 - so on ) - /home/john
- group(john) - shell - /bin/bash /bin/sh

===================================================================================
==========================
Configuration files:
===================================================================================
===========================
* /etc/passwd -> User details

cat /etc/passwd
root :x :0 :0 :root :/root
:/bin/bash
user name placeholder userid groupid comment/fullname home dir
shell
for password

ec2-user :x :1000 :1000 :Cloud User :/home/ec2-


user :/bin/bash
user name placeholder userid groupid comment/fullname home dir
shell
==================================================================================
* /etc/shadow -> password details

cat /etc/shadow
ec2-user :!! :19451:0:99999:7:::
username password
[root@ip-172-31-5-75 ~]# chage -l ec2-user
Last password change : Apr 04, 2023
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
[root@ip-172-31-5-75 ~]#
==================================================================================
* /etc/group -> Group details and which user is assigned to which group
==================================================================================
cat /etc/group
systemd-journal :x :190 :ec2-user
groupname placeholder groupid username ( users assigned to
systemd-journal )
===================================================================================
===========================
User creation :
===================================================================================
==========
syntax: useradd user_name
eg : useradd john
useradd -d /home/johnsmith -s /bin/sh smith
useradd --help

syntax : passwd user_name


* passwd john

[root@ip-172-31-5-75 ~]# passwd smith


Changing password for user smith.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@ip-172-31-5-75 ~]#

Note : passwd --> press enter ( whichever user is logged in his password will be
changed)
===================================================================================
==
Delete User :
===================================================================================
==
Syntax : userdel john
===================================================================================
==
Group Creation :
===================================================================================
==
Syntax : groupadd group_name

* eg : groupadd developers

Assign user to Group:


* usermod -G developers smith
* usermod -s /bin/bash smith

syntax:

=======================================
Modify any user details:
=======================================
usermod -d /home/smith smith
============================================
Switch to root : sudo su / sudo su - root
Switch to normal user : su - john
===================================================================================
===========
Delegate root Privileges
===================================================================================
==============
visudo -> /etc/sudeors -> sudo privileges
smith -> visudo
root ALL=(ALL) ALL
smith ALL=(ALL) ALL

smith commands : sudo yum install zip


sudo useradd ravi

Ravi commands:
* yum install zip -y -> Error: This command has to be run with superuser
privileges (under the root user on most systems).
* sudo yum install zip -y -> ravi is not in the sudoers file. This
incident will be reported.
===================================================================================
==========================
Permissions:
===================================================================================
==========================

r - read - 4
w - write - 2
x - execute -1

File:
- rw- r-- r--
420 400 400
6 4 4

Default permission of File : 644

Directory :
d rwx r-x r-x
421 401 401
7 5 5

Default permission of Directory : 755

Command : chmod -> change modification


eg : chmod 444 file1 -> --- --- ---
r-- r-- r--
4 4 4

-R recursive permissions

chmod -R 777 Dir_name


===================================================================================
================
chown - change ownership

* syntax : chown user_name: group_name file/dir


eg : chown smith:smith f1
chown -R smith:smith test
===================================================================================
=======================
Package Management:
===================================================================================
=======================
Windows : Download -> xyz.exe -> Double click
Windows: software
Linux : package

Linux : package managers


* RPM : Redhat package manager
* YUM : Yellow dog update modifier

* RPM : Redhat package manager : ( 3,4,5(yum))


- Any package extension .rpm
- RPM installs only single package, that means dependent softwares are not
installed automatically.
- You need to know/have complete name/path of package.
- Specific version of package info is required

command :
* Downlaod the rpm file from offical website
* rpm -ivh jenkins-2.23.45.x86.rpm --> Install rpm
* rpm -qa | grep -i java --> to check package is installed or not
* rpm -e jenkins-2.23.45.x86 --> delete/remove/erase package
* rpm -Uvh jenkins-2.45.45.x86.rpm -> Upgrade the package

-i install
-v verbose ( detailed output)
-h hash formatting - ####### 100%
-q query
-a all
===================================================================================
==================
[root@ip-172-31-14-11 ~]# rpm -ivh jenkins-2.346.1-1.1.noarch.rpm
warning: jenkins-2.346.1-1.1.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID
45f2c3d5: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:jenkins-2.346.1-1.1 ################################# [100%]
[root@ip-172-31-14-11 ~]#
===================================================================================
==================
[root@ip-172-31-14-11 ~]# rpm -qa | grep -i jenkins
jenkins-2.346.1-1.1.noarch
[root@ip-172-31-14-11 ~]# rpm -Uvh jenkins-2.361.2-1.1.noarch.rpm
warning: jenkins-2.361.2-1.1.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID
45f2c3d5: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:jenkins-2.361.2-1.1 ################################# [ 50%]
Cleaning up / removing...
2:jenkins-2.346.1-1.1 ################################# [100%]
[root@ip-172-31-14-11 ~]# rpm -qa | grep -i jenkins
jenkins-2.361.2-1.1.noarch
[root@ip-172-31-14-11 ~]#
===================================================================================
==================
[root@ip-172-31-14-11 ~]# rpm -qa | grep -i jenkins
jenkins-2.361.2-1.1.noarch
[root@ip-172-31-14-11 ~]# rpm -e jenkins-2.361.2-1.1.noarch
[root@ip-172-31-14-11 ~]# rpm -qa | grep -i jenkins
[root@ip-172-31-14-11 ~]#
===================================================================================
==================
* YUM : Yellow dog update modifier : (5,6,7,8,9(yum))
- No need to mention full package name.
- Not mandatory to mention version/architecture
- Installation of dependencies are taken care by yum.

Commands:
* yum install httpd -> install package
* yum remove httpd -> remove/uninstall package
* rpm -qa | grep -i java --> to check package is installed or not
* yum upgrade httpd -> upgrade to latest version

* yum update -y -> all installed package in machine are upgraded.


yum -> /etc/yum.repos.d/redhat.repo
/etc/yum.repos.d/jenkins.repo

vi /etc/yum.repos.d/jenkins.repo
[name]
name: jenkins repo
baseurl/Mirrors: URL of cloud/onedrive/packages are kept ->
http://cloud.package.com/repos/jenkins/
enabled=0/1
gpgcheck=1/0
gpgkeys: /etc/certs/jenkins.certs
===================================================================================
======================
Backup and Restore :
===================================================================================
======================
1. TAR : Tape Archieve :
* Backup files within 10 GB and further we can restore file from tar file.
* Tar provides flexibility to bundle the files and directories with compress
format.
* We can transfer these compress files to other location.

eg : Packages bundling/extracting, installation files tars, logs files etc

Commands:
eg : file1 file2 file2 file4
* tar -cvf file.tar file1 file2 file2 file4
* tar -cvf file.tar file* jenkin.txt
* tar -cvf latest.tar *.txt
-c create
-v verbose
-force

Compress :
* tar -cvzf file.tar.gz file1 file2 file2 file4
* tar -cvzf file.tar.gz file.tar

Extraction :
* tar -xvf file.tar
* tar -xvzf file.tar.gz
* tar -xf file.tar.gz
* tar -xvf file.tar.gz

-x extract
-v verbose
-f force
=========================================================
Display the contents of tar file without extracting :
=========================================================
* tar -tvf file.tar
* tar -tvf file.tar.gz

output :
[root@ip-172-31-14-11 ~]# tar -cvf file.tar f1 f2 f3 f4 f5
f1
f2
f3
f4
f5
[root@ip-172-31-14-11 ~]# ls -lrt
total 179988
-rw-r--r--. 1 root root 90996766 Jun 22 2022 jenkins-2.346.1-1.1.noarch.rpm
-rw-r--r--. 1 root root 93292860 Oct 5 10:27 jenkins-2.361.2-1.1.noarch.rpm
-rw-r--r--. 1 root root 0 Apr 5 04:57 f5
-rw-r--r--. 1 root root 0 Apr 5 04:57 f4
-rw-r--r--. 1 root root 0 Apr 5 04:57 f3
-rw-r--r--. 1 root root 0 Apr 5 04:57 f2
-rw-r--r--. 1 root root 0 Apr 5 04:57 f1
-rw-r--r--. 1 root root 10240 Apr 5 04:58 file.tar
[root@ip-172-31-14-11 ~]# du -sh *
0 f1
0 f2
0 f3
0 f4
0 f5
12K file.tar
87M jenkins-2.346.1-1.1.noarch.rpm
89M jenkins-2.361.2-1.1.noarch.rpm
[root@ip-172-31-14-11 ~]#
[root@ip-172-31-14-11 ~]# tar -cvzf file.tar.gz file.tar
file.tar
[root@ip-172-31-14-11 ~]# ls -lrt
total 179992
-rw-r--r--. 1 root root 90996766 Jun 22 2022 jenkins-2.346.1-1.1.noarch.rpm
-rw-r--r--. 1 root root 93292860 Oct 5 10:27 jenkins-2.361.2-1.1.noarch.rpm
-rw-r--r--. 1 root root 0 Apr 5 04:57 f5
-rw-r--r--. 1 root root 0 Apr 5 04:57 f4
-rw-r--r--. 1 root root 0 Apr 5 04:57 f3
-rw-r--r--. 1 root root 0 Apr 5 04:57 f2
-rw-r--r--. 1 root root 0 Apr 5 04:57 f1
-rw-r--r--. 1 root root 10240 Apr 5 04:58 file.tar
-rw-r--r--. 1 root root 183 Apr 5 04:59 file.tar.gz
[root@ip-172-31-14-11 ~]# du -sh *
0 f1
0 f2
0 f3
0 f4
0 f5
12K file.tar
4.0K file.tar.gz
87M jenkins-2.346.1-1.1.noarch.rpm
89M jenkins-2.361.2-1.1.noarch.rpm
[root@ip-172-31-14-11 ~]#

[root@ip-172-31-14-11 ~]# tar -tvf new-file.tar.gz


-rw-r--r-- root/root 0 2023-04-05 04:57 f1
-rw-r--r-- root/root 0 2023-04-05 04:57 f2
-rw-r--r-- root/root 0 2023-04-05 04:57 f3
-rw-r--r-- root/root 0 2023-04-05 04:57 f4
-rw-r--r-- root/root 0 2023-04-05 04:57 f5
-rw-r--r-- root/root 10240 2023-04-05 04:58 file.tar
-rw-r--r-- root/root 183 2023-04-05 04:59 file.tar.gz
[root@ip-172-31-14-11 ~]#

[root@ip-172-31-14-11 ~]# tar -xf new-file.tar.gz


[root@ip-172-31-14-11 ~]# echo $?
0
[root@ip-172-31-14-11 ~]# ls -lrt
total 20
-rw-r--r--. 1 root root 0 Apr 5 04:57 f5
-rw-r--r--. 1 root root 0 Apr 5 04:57 f4
-rw-r--r--. 1 root root 0 Apr 5 04:57 f3
-rw-r--r--. 1 root root 0 Apr 5 04:57 f2
-rw-r--r--. 1 root root 0 Apr 5 04:57 f1
-rw-r--r--. 1 root root 10240 Apr 5 04:58 file.tar
-rw-r--r--. 1 root root 183 Apr 5 04:59 file.tar.gz
-rw-r--r--. 1 root root 465 Apr 5 05:04 new-file.tar.gz
[root@ip-172-31-14-11 ~]#
===================================================================================
==========================
2. ZIP : * Backup files within 10 GB and further we can restore file from zip
file.
* Tar provides flexibility to bundle the files and directories with compress
format.
* We can transfer these compress files to other location.

eg : Packages bundling/extracting, installation files zip , logs files etc

package : yum install zip -y

Commands:

Creating zip files :

* zip -r file.zip f1 f2 f3 f4
* zip -r file.zip f*

-r recursive

Extract files:

* unzip file.zip

[root@ip-172-31-14-11 ~]# zip -r file.zip f1 f2 f3 f4 f5


adding: f1 (stored 0%)
adding: f2 (stored 0%)
adding: f3 (stored 0%)
adding: f4 (stored 0%)
adding: f5 (stored 0%)
[root@ip-172-31-14-11 ~]# ls -lrt
total 24
-rw-r--r--. 1 root root 0 Apr 5 04:57 f5
-rw-r--r--. 1 root root 0 Apr 5 04:57 f4
-rw-r--r--. 1 root root 0 Apr 5 04:57 f3
-rw-r--r--. 1 root root 0 Apr 5 04:57 f2
-rw-r--r--. 1 root root 0 Apr 5 04:57 f1
-rw-r--r--. 1 root root 10240 Apr 5 04:58 file.tar
-rw-r--r--. 1 root root 183 Apr 5 04:59 file.tar.gz
-rw-r--r--. 1 root root 465 Apr 5 05:04 new-file.tar.gz
-rw-r--r--. 1 root root 682 Apr 5 05:09 file.zip
[root@ip-172-31-14-11 ~]# du -sh *
0 f1
0 f2
0 f3
0 f4
0 f5
12K file.tar
4.0K file.tar.gz
4.0K file.zip
4.0K new-file.tar.gz
[root@ip-172-31-14-11 ~]#

[root@ip-172-31-14-11 ~]# unzip file.zip


Archive: file.zip
extracting: f1
extracting: f2
extracting: f3
extracting: f4
extracting: f5
[root@ip-172-31-14-11 ~]# ls -lrt
total 24
-rw-r--r--. 1 root root 0 Apr 5 04:57 f5
-rw-r--r--. 1 root root 0 Apr 5 04:57 f4
-rw-r--r--. 1 root root 0 Apr 5 04:57 f3
-rw-r--r--. 1 root root 0 Apr 5 04:57 f2
-rw-r--r--. 1 root root 0 Apr 5 04:57 f1
-rw-r--r--. 1 root root 10240 Apr 5 04:58 file.tar
-rw-r--r--. 1 root root 183 Apr 5 04:59 file.tar.gz
-rw-r--r--. 1 root root 465 Apr 5 05:04 new-file.tar.gz
-rw-r--r--. 1 root root 682 Apr 5 05:09 file.zip
[root@ip-172-31-14-11 ~]#
===================================================================================
================
3. dd : Device drivers -> 100 GB backup of disks
command : dd if=/dev/sba of=/dev/sbb
if -> input file
of -> output file
===================================================================================
===================

You might also like