======================== Why to learn Linux OS ? ======================== 1) In Real-Time, all devops tools will be installed on linux machines. Ex: jenkins, docker, k8s, jfrog, nexus, sonar, ELK... 2) Database servers will be instaled on Linux machines. 3) Application deployment will happen in linux machine 4) Application log files will be stored in linux machine ========================= What is Operating System ========================= => OS is a software which acts as mediator between users and computers. => Without OS we can't use any computer. => We have several Operating systems in the market Ex: Windows, Unix, Linux, Mac, android, IOS etc.. ============= Windows OS ============= => Developed by Microsoft => Licensed software => Single user based OS => Security is very less (anti virus s/w required) => It is GUI based OS => It is recommended for personal use Ex: watch movies, play games, prepare docs, online classes, coding etc.... =========== Linux OS =========== => Community based OS (free and open source) => Multi User based OS => Security is very high => Linux supports both GUI and CLI => Highly recommended for business systems Ex: DB servers, App servers, DevOps tools... ============== Linux History ============== => Linux OS developed by "linus torvalds" in 1991 (Li)nus Torvalds + Mi(nux) = Linux => He released Linux OS into market with free of cost. => Many companies downloaded linux os source code and modified according to their requriement and released into market with different names those are called as Linux Distributions. Ex : Ubuntu, Red Hat, Cent OS, Kali, Debina, SUSE, FEDORA... Note: We have 200+ linux distributions in the market. ================== Environment Setup ================== 1) Download and install Linux OS in a computer directley 2) Install Linux as Guest OS using Virtual Box. 3) Create Linux VM in cloud (AWS) ============== Assignment =============== 1) Create AWS Free Tier account 2) Create Linux VM in aws cloud and connect with that using SSH Client s/w (git bash / mobaxterm/ putty) Reference Videos : https://www.ashokit.in/yt-content/cloud-tutorials ==================== Linux Architecture ==================== 1) Shell 2) Kernel 3) Hardware components ================ What is shell ? ================ => Shell is a mediator between users and kernel => When we execute linux command then shell will convert that command into kernel understandable format. =================== What is kernel ? =================== => Kernel is mediator between shell and hardware components => Kernel is core component of Linux OS => Kernel is responsible to convert shell given instructions into system hardware components. ================== Linux File System ================== => In linux vm everything will be represented as a file only => Linux machine entryponint is (/) root / (root) - /home - /bin - /etc - /opt - /usr - /temp - /mnt ============================================================ /home : It contains user home directories Note: For every user account, one home directory will be available like below. ec2-user : /home/ec2-user john : /home/john smith : /home/smith ashok : /home/ashok /etc : It contains system related configuration files /opt : It is used to install software packages (ex: java, tomcat, mvn) /usr : It is used to host software applications /var : It is used to host static websites (html pages) ================ Linux Commands ================ whoami : display currently logged in username pwd : print working directory date : display current date cal : display current month calendar cal 2050 : display 2050 year calendar ===================================== Working with Files and Directories ===================================== cd : change directory cd cd .. ls : list files ls ls -l (alphabetical order) ls -lr (reverse of alphabetical order) ls -lt (latest files on top) ls -ltr (old files on top) ls -la (hidden files) ls -l (print dir content) mkdir : To create directory mkdir java mkdir devops aws rmdir : To remove directory (empty directories) rmdir touch : To create empty files touch f1.txt touch f2.txt f3.txt f4.txt rm : To remove files and non-empty directory rm rm -rf cat : create file with data + append data + print file data // create new file with data cat > f1.txt // append data to file cat >> f1.txt // print file data from top to bottom cat f1.txt // print data with line nos cat -n f1.txt tac : print file data from bottom to top cp : copy data from one file to another file cp f1.txt f2.txt Note: To copy data from more than one file we should use cat command cat f1.txt f2.txt > f3.txt mv : rename files and directories + move from one location to another location mv f1.txt ashokit.txt mv f2.txt devops/ wc : word count. It is used to print no.of lines, no.of words and no.of chars available in the file wc f1.txt ============= Text Filters ============= head : To print first 10 lines of the file head f1.txt head -n 30 f1.txt head -n 50 f1.txt tail : To print last 10 lines of the file tail app.log tail -n 50 app.log tail -n 100 app.log tail -f app.log grep : global regular expression print => It is used to search for keywords in the file // print lines which contains Exeception keyword grep 'Exception' app.log // ignore case-sensitive grep -i 'Exception' app.log // print along with line numbers grep -n 'Exception' app.log // print lines which doesn't contains Exception keyword grep -v 'Exception' app.log ============= Text Editors ============= => We will use 'vi' (visual editor) $ vi Note: If file already available it open existing file only, if file not available it will create and open that file. => Visual Editor works in 3 modes 1) Command mode (read file data) 2) Insert Mode (press 'i' in keyword) 3) Esc Mode (press 'esc' in keyboard) => When we are in insert mode we can save and close the file using below options Save changes and close file => press :wq Ignore changes and close file => press :q! ==================== Networking Commands ==================== ifconfig : To get ip address of machine wget : To download files from internet syntax : wget Ex : wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.102/bin/apache-tomcat-9.0.102.zip curl : To send HTTP request to URL syntax : curl Ex : curl https://dummyjson.com/quotes/random ping : To check network connectivity Syntax : ping ping www.google.com ping 192.168.1.101 ================ User Management ================ -> Linux OS is a multi user based OS -> Multiple Users can connect with linux vm at a time. Note: When we create linux vm using "Amazon Linux" AMI we will get 'ec2-user' as a default user with sudo priviliges. SUDO : Super user doing operation # check users available cat /etc/passwd # create new user Syntax : sudo useradd Ex : sudo useradd john # set password for user Syntax : sudo passwd Ex : sudo passwd john ================================ What is sudoers file in linux ? ================================ Note: To give sudo priviliges for the users we need to add them in sudoers file. # open sudoers file sudo visudo Note: Configure user like below (just below root user) john ALL=(ALL) ALL smith ALL=(ALL) ALL Note: After adding user, close that file using "CTRL + X + Y + Enter" =================================================== How to enable password based authentication in linux ? =================================================== => In Linux VM by default PasswordAuthentication is disabled. => If we want to connect with Linux vm using username and password we need to enable that. # open sshd_config file sudo vi /etc/ssh/sshd_config => Find the Line containing ‘PasswordAuthentication’ parameter and change its value from ‘no’ to ‘yes’ Note: save that file and close it using :wq + Enter # restart sshd service sudo service sshd restart # exit from the machine exit # connect with linux vm usng john user # open gitbash # execute ssh command ssh john@public-ip ================== File Permissions ================== => File permissions are divided into 3 types a) read (r) b) write (w) c) execute (x) => File permissions will be represented like below Ex : -rwxrwxrwx f1.txt drwxrwxrwx ashokit => First 3 characters will represent owner permissions (the user who created that file) => Middle 3 characters will represent group permissions. => Last 3 characters will represent other users permissions. Ex: -rw-r-xr-x f1.txt owner => read + write group => read + execute others => read + execute -rwx------ f2.txt owner : read + write + execute group : Nothing Others: Nothing => To add or remove file permissions we will use 'chmod' command. # add execute permission for user(owner) chmod u+x f1.txt # remove write permission for user(owner) chmod u-w f1.txt # add write and execute permissions for group chmod g+wx f1.txt # remove read permission for others chmod o-r f1.txt => We can represent file permissions using numeric numbers also. 0 => No Permissions 1 => Execute 2 => Write 3 => (2+1) => Write + Execute 4 => Read 5 => (4+1) => Read + Execute 6 => (4+2) => Read + Write 7 => (4+2+1) => Read + Write + Execute # user-read, group-write, others- r+e chmod 425 f1.txt # u+rw, g+w, o+we chmod 623 f1.txt #u-rwx, g-rwx , o+rwx chmod 7 f1.txt #u-rwx, g+rwx , o+rwx chmod 77 f1.txt ====================================== How to change ownership of the file ? ====================================== => using chown command we can change ownership $ sudo chown ashok f1.txt ================== Package Managers ================== Package : A software => Package managers are used to manage softwares installation in linux machines. => Package Managers are specific to linux distribution. yum : amazon linux, cent os apt : ubuntu , debian rpm : red hat # install git sudo yum install git -y git --version whereis git # install java sudo yum install java -y java -version whereis java # install maven sudo yum install maven -y maven -version whereis maven