Linux Notes
Linux Notes
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.
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
-l long listing
-r recursive
-t formatting
File:
Directory:
===================================================================================
5. display output of files
cat /path/of/file
eg : cat file.txt
===================================================================================
=
6. Directory creation
eg : mkdir test
cd test -> mkdir test1
cd test1 -> mkdir test2
cd test2 -> mkdir test3
eg : mkdir -p test-sample/test111/test222/test333
====================================================================
rm -rf *
-r recursive
-f force
=====================================================================
9. Create file
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
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
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
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
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
Directory :
d rwx r-x r-x
421 401 401
7 5 5
-R recursive permissions
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
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.
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 ~]#
Commands:
* zip -r file.zip f1 f2 f3 f4
* zip -r file.zip f*
-r recursive
Extract files:
* unzip file.zip