==================== Date : 23-Sep-2024 Topic : Linux OS ==================== => Where we will use linux os in real-time => Jenkins Server => Docker Server => K8S Cluster => SonarQube Server => Nexus Server => Ansible Server => To setup all above servers/tools we will use Linux machines only. ============= What is OS ? ============= => It is a software which acts as mediator between user and computer. => Users will communicate with computers using OS. => Without OS we can't use any computer. => OS provides platform to run our applications in computer. Ex: notepad, paint, calculator, browser, tomcat.... => We have several operating systems in market Ex: Windows, Linux, Mac, Android, IOS.... =========== Windows OS =========== => Developed by Microsoft company (Bill Gates). => Windows os is licensed (commercial) => Windows is single user based os. => Windows is GUI based (graphical user interface) => Security features are less in windows os (anti virus s/w required) => Windows is recommended for personal use Ex: watch movies, play games, online classes.... ========== Linux OS ========== => Linux is community based os (not specific to any company) => Linux is free and open source os. => Linux is Multi User based OS. => Linux is highly secured (anti virus is not required) => Linux is both GUI & CLI based os (command line interface) => Linux is highly recommended for business use (servers management) Ex: Webservers, DB Servers, Jenkins, Docker, K8S, Ansible.... ============== Linux History ============== => Linux OS developed by "Linus Torvalds" -> Linus Torvalds identified some challenges/issues in "Unix OS". -> Linus Torvalds identified one OS which is matching with his ideas. i.e Minux os -> Linus Torvalds used Minux OS code and made some changes and released into market as new OS i.e Linux OS. (Li) nus + Mi (nux) = Linux ====================== Linux Distributions ====================== -> Linus Torvalds provided Linux OS source code for free of cost. -> So many companies downloaded Linux OS source code and modified according to their requirement and released into market with their brand names. Those are called as Linux Distributions. Ex: Amazon Linux, Ubuntu, Red Hat, Cent OS, Kali, SUSE, Fedora.... Note: We have 200+ Linux Distributions in the market. ============================= How to setup Linux Machine ? ============================= Approach-1 : Take machine & install Linux OS. Approach-2 : Install linux os as guest os using Virtual Box. Approach-3 : Setup Linux VM in cloud and connect with that. ======================================================== 👉 AWS Account Setup : https://youtu.be/xi-JDeceLeI?si=4MgBX_H4_NPuzdT8 👉 Connect Linux VM with MobaXterm : https://youtu.be/uI2iDk8iTps?si=ZuZs0lQTxoRpbRMk 👉 Connect Linux VM with putty : https://youtu.be/GXc_bxmP0AA?si=HgSydrP89mPxv23s 👉 Connect Linux VM with GitBash : https://www.youtube.com/watch?v=JMlQaTXvw5o ==================== Date : 24-Sep-2024 Topic : Linux OS ==================== ================================ Linux Architecture Components =============================== 1) Applications / Commands 2) Shell 3) Kernel 4) Hardware Components =================== What is shell ? =================== => Shell acts as mediator between user and kernel. => Shell is responsible to process user given commands. Note: when we execute a command, shell verify command syntax. If commad is valid then shell will convert that command into kernel understable format. # check default shell of our linux vm echo $SHELL ========================== What is Kernel in linux ? ========================== => Kernel is heart of Linux OS => Kernel is a mediator between SHELL and Hardware components. => Kernel will get instructions from shell then kernel will convert those instructions into hardware understandable format. # print kernel version $ uname -r =============================== Linux File System Hierarchy =============================== =============== Linux Commands =============== whoami pwd date cal cal 2025 cal 5 2025 cd / cd /home/ec2-user ec2-user : /home/ec2-user ashok : /home/ashok raju : /home/raju ========================= Date : 25-Sep-2024 Topic : Linux Commands ========================= ============================================= working with directories and files in linux ============================================= mkdir : make directory mkdir abc aws devops rmdir : remove empty directory rmdir abc Note: To delete non-empty directories we will use below command rm -rf touch : to create empty files touch f1.txt f2.txt f3.txt ls : display present working directory content ls -l : long list the files in alphabetical order ls -lr : display files in reverse of alphabetical order ls -lt : display latest files on top ls -ltr : display old files on top ls -la : display hidden files cd : to change directory cd cd .. ls -l rm : to delete file rm f1.txt rm -rf mv : For rename & move mv existing-name new-name mv presention-location new-location cat : create new file with data + append data to file + print file data # create new file with data cat > f1.txt # append data to existing file cat >> f1.txt # print file data cat f1.txt # print file data along with line numbers cat -n f1.txt tac : To print file data from bottom to top cp : copy file data from one file to another file cp f1.txt f2.txt Note: If we want to copy data from multiple files then we should use cat command. cat f1.txt f2.txt > f3.txt ========================= Date : 26-Sep-2024 Topic : Linux Commands ========================= head : print first 10 lines of the file head f1.txt head -n 20 f1.txt head -n 50 f1.txt tail : print last 10 lines of the file tail f1.txt tail -n 25 f1.txt grep : gloabl regular expression print => Using grep command we can search for content in the file # print lines which contains admin keyword grep 'admin' data.txt # print lines which contains nexus keyword grep 'nexus' data.txt # ignore case grep -i 'nexus' data.txt # print lines which contains nexus keyword with line numbers grep -n 'nexus' data.txt # search in all files of pwd grep -n -i 'Nexus' * # print lines which doesn't contains teen keyword grep -v 'teen' f1.txt # check for 'tw' keyword in last 10 lines of file tail f1.txt | grep 'tw' ======================= Text Editors in Linux ======================= => vi (visual editor) it is default editor in linux machines. => Using 'vi' we can create new files and we can modify existing file data. $ vi aws.txt => vi command is having 3 modes 1) command mode (just to open the file) Ex: vi 2) insert mode (to edit the file ) ---> press 'i' in keyboard 3) esc mode (to comeout from insert mode) --> press 'esc' in keyboard ## Save changes & close the file => :wq ## Without saving changes close the file => :q! Note: vi command will open the file if it is avilable otherwise it will create new file and it will open that file. ======================= file creation commands ======================= touch : to create empty file cat : create file with data cp : copy one file data into another file (cp f1.txt f2.txt) vi : create and open file for editing (vi f3.txt) ==================== reading file data ==================== cat : print file data from top to bottom tac : print file data from bottom to top head : print first 10 lines of file data tail : print last 10 lines of file data vi : open the file grep : filter the data (search the data) ============= SED Command ============= => SED stands for stream editor => SED is used to process the data (substitute, delete, print, insert) => Using SED command we can perform operations on the file without opening the file. => SED is very powerful command in linux # replace first occurance of linux keyword with unix sed 's/linux/unix/' data.txt # replace second occurance of linux keyword with unix sed 's/linux/unix/2' data.txt # replace 3rd occurance of linux keyword with unix sed 's/linux/unix/3' data.txt # replace all occurances of linux keyword with unix sed 's/linux/unix/g' data.txt # substitute and save changes in original file sed -i 's/linux/unix/g' data.txt # delete first line of the file sed -i '1d' data.txt # delete fourth line of the file sed -i '4d' data.txt # delete data from nth line to last line sed -i 'n,$d' data.txt Note: n is a number # delete data from 5th line to 15th line sed -i '5, 15d' data.txt # insert data at 2nd line sed '2i\i love india' data.txt # insert data at last line sed '$a\i am from ashokit' data.txt ========================= Date : 27-Sep-2024 Topic : User Management ========================= => Linux is a multi user based OS. => Multiple users can acces single linux machine and can perform multi tasking at time. Note: "ec2-user" is a default user in amazon linux vm. Note: ec2-user having sudo priviliges (administrator). => Within one linux machine we can create multiple user accounts. => when we create user account, for user one home directory will be created. ec2-user => /home/ec2-user john => /home/john smith => /home/smith # create user sudo useradd # set password for user & update pwd for user sudo passwd # display all users created cat /etc/passwd # swith user account su # navigate to logged in user home directory cd ~ # Delete user $ sudo userdel # Delete user along with user home directory $ sudo userdel --remove # how to change username $ sudo usermod -l /etc/passwd: This file Contains general user information. /etc/shadow: This file Contains hashed passwords and other security-related information. =================================== Working with user groups in linux =================================== => When we create user in linux, for every user one user group also will be created with the given username. # Display all groups in linux $ cat /etc/group # Create group in linux $ sudo groupadd # Adding user to group $ sudo usermod -aG # Remove user from the group $ sudo gpasswd -d # display users belongs to a group $ sudo lid -g # display user belongs to which groups $ id # delete group $ sudo groupdel # changing group name $ sudo groupmod -n ================================= What is sudoers file in Linux ================================= => It is very important configuration file in linux machine. => By Using this file we can control which user can run linux command as a superuser. # print sudoersfile content sudo cat /etc/sudoers # check root user priviliges sudo grep 'root' /etc/sudoers Note: We should be very careful while working with sudoers file. If we do any mistakes in sudoers file then we can't use that user account. ########## Giving sudo previliges for user ####### # open sudoers file sudo visudo Note: goto root user details, add one our user just below root user like below # add user like below ashok ALL=(ALL) ALL => After making above changes, to close sudoers file => ( CTRL + X + Y + Enter ) ===================================================================== How to enable password based authentication for users in linux vm? ===================================================================== => In linux vm, by default passwordauthentication is no => If we want to connect with linux vm using username and password then we need to set that value as yes. => To enable password authentication we need to modify "sshd_config" file in linux. # Display sshd_configurration file data $ sudo cat /etc/ssh/sshd_config # Open file $ sudo vi /etc/ssh/sshd_config Note: Go to insert mode and enable pwdbasedauthentication as yes # restart sshd service # sudo systemctl restart sshd Note : Now we can connect with linux vm using username and pwd # use below command in gitbash to connect ssh username@public-ip ===================================================== Date : 30-Sep-2024 Topic : chmod + chown + zip + networking commands ===================================================== => Using file permissions we can secure our files and we can protect our file data. => We have 3 types of permissions in linux r => read w => write x => execute => file/directory permissions will be represented like below rwxrwxrwx f1.txt => file permissions contains 9 characters are divided into 3 parts first 3 characters => user/owner permissions middle 3 characters => group permissions last 3 characters => other users permissions => Lets under file permissions with diff scenarios Scenario-1 :: rw-r--r-- f1.txt user : read + write group : read others : read Scenario-2 :: rwxr-xr-x f1.txt user : read + write + execute group : read + execute others : read + execute Scenario-3 : rwx--xr-x f1.txt user : read + write + execute group : execute others : read + execute => To change file/directory permissions we will use 'chmod' command + => to add permission - => to remove permission # Giving execute permission for user $ chmod u+x f1.txt # giving write permission for group $ chmod g+w f1.txt # Remove execute permission for others $ chmod o-x f1.txt # give all permissions for group $ chmod g+rwx f1.txt # Remove all permissions for others $ chmod o-rwx f1.txt ==================================== File Permissions in Numeric Format ==================================== 0 => No permission 1 => Execute 2 => Write 3 => (2 + 1) => Write + Execute 4 => Read 5 => (4 + 1) => Read + Execute 6 => (4 + 2) => Read + Write 7 => (6 + 1) => Read + Write + Execute # ugo+x chmod 111 f1.txt # ugo+w chmod 222 f1.txt # u+rwx g+rw o+rx chmod 765 f1.txt # u+r g+rx o+rw chmod 456 f1.txt # ugo+rwx chmod 777 f1.txt # u-rwx g-rwx o+rwx chmod 007 f1.xt =============== chown command =============== => It is used to change file/directory ownership # change owner sudo chown new-owner file/directory # change owner-group sudo chown :new-group file/directory # change owner & group of file/directory sudo chown new-owner:new-group file/directory ============================================ Q) What is the diff between chmod & chown ? ============================================ chmod => To change file/directory permissions chown => To change owner/group ================================= Working with Zip files in linux ================================= => Zip is used for files archieve (compress) ## syntax to create zip file zip # create some empty files touch f1.txt f2.txt f3.txt # create zip file with content zip ashokit_data *.txt # unzip the zip file unzip ashokit_data.zip ====================== Networking commands ====================== ping : To check connectivity of other servers ping www.google.com ping www.facebook.com ping 192.168.2.009 wget : It is used to download files from internet based on given url wget https://dlcdn.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.zip curl : It is used to send HTTP Request to server curl https://dummyjson.com/quotes/random ifconfig: To get ip address of our machine ===================================================== Date : 01-Oct-2024 Topic : Linux Commands ===================================================== find : it is used to search files & directories in linux machine # search for the files which are having name as f1.txt sudo find /home -name f1.txt # search for empty files inside /home sudo find /home -type f -empty # search for empty directories inside /home sudo find /home -type d -empty uptime : from when our linux vm is running free : to display memory details top : display running processes ===================== process management ===================== # display running process ps aux Note: Every process will process id (PID) # kill the process kill -9 ============================================= How to change hostname in vm (temporarly) ? ============================================= # set hostname $ sudo hostname # re-start session $ exit Note: connect back to vm then we can see configured hostname =================================== How to set hostname permanentley =================================== # update hostname in below file $ sudo vi /etc/hostname # restart the vm Note: After restart hostname configured in file will be reflected in terminal. ========================== Package Managers in Linux ========================== => Package means a software Ex: git, maven, java, python etc..... => Package managers are used to "install/upgrade/remove" software packages in linux machines. => Package managers are specific to linux distribution. Amazon Linux / Red Hat Linux / cent os : yum Ubuntu / Debian Linux : apt # check git client installed or not git --version # install git client s/w sudo yum install git # check git installation path whereis git # check java installed or not java -version # install java s/w sudo yum install java # check java installation path whereis java ====================================================== Assignment : Remove git and java from linux machine ====================================================== ============================= Webserver Setup in Linux VM ============================ => Webserver is a software which is used to run websites. => Website means collection of web pages Ex: login page, registration page, forgot pwd page, dashboard page... => Websites are divided into 2 types 1) Static website 2) Dynamic website => The website which gives same response for every user is called as static website. => The website which gives response based on logged in user is called as dynamic website. Ex: gmail, facebook, instagram.... => To run static websites we can use 'httpd' as webserver. => To run dynamic websites we can use "tomcat, iis" as webserver ================================ Static website hosting in linux ================================ # install webserver $ sudo yum install httpd -y # start webserver $ sudo service httpd start Note: httpd webserver runs on HTTP protocol with 80 as port number. => To access our webserver we need to enable 80 port number in security group inbound rules. => We can access our webserver using ec2-vm public ip. # Navigate to website content directory $ cd /var/www/html # create index.html file and write a msg in that file $ sudo vi index.html Note: After saving index.html access EC2 VM public ip in browser. ================================ What is systemctl in linux ? ================================ => systemctl is used to manage services in linux machines. It is called as Service Manager. => using systemctl we can perform below operations a) start a service b) stop a service c) restart a service # check status of httpd sudo systemctl status httpd # stop httpd server sudo systemctl stop httpd # start httpd server sudo systemctl start httpd # reload service sudo systemctl reload http ========= Summary ========= 1) What is OS 2) Windows Vs Linux 3) Linux History + Distributions 4) Linux VM setup in AWS cloud 5) Connect with Linux VM using SSH Clients - MobaXterm - Putty - GitBash 6) Working with Directories & Files 7) Text Editors (vi & sed) 8) Text Filters (head, tail, grep) 9) User Management & Groups 10) How to enable pwd based authentication 11) File Permissions (chmod) 12) File Ownership (chown) 13) Archieves (zip + unzip) 14) Network Commands 15) Package Managers 16) Static Website Hosting in Linux (httpd) 17) Service Management (systemctl) 18) Process Management 19) Changing Hostname 20) sudoers file + sshd_config file 21) Linux Architecture 22) Linux File System