echo "Hello world"
We are going to learn:
- User / group
- grep, awk, find.
- File permission
- ssh/scp
- systemctl
Groups: collection of users
sudo groupadd devopsuse the
/etc/groupfile to get groupsWhenever you create a user it creates groups also with the same name.
Add user to group
whenever you add a user to a group you modify the user.
sudo usermod -aG devops user1To add multiple users, we can also use gpasswd to add user
sudo gpasswd -M user1,user2,user3 testersDelete user form group
sudo gpasswd -d user2 testersDelete group
sudo groupdel testersUse chgrp to change group of file
sudo chgrp tester file.txt
File permissions:
Numeric Permissions:
- r - read = 4
- w - write = 2
- x - execute = 1
There are three set of permissions for:
- U - User/Owner
- G - Group
- O - Others
Combinations
_ U _ . _ G _ . _ O _ => rwx rwx rwx
Example:
U - read+write = 4+2 => 6
G - read+executable = 4+1 => 5
O - read = 4 => 4
Final permission numeric == 654
User
chmodcommand to modify permissionschmod 700 file.txt
Find files
Grep: To find anything inside file or name of files.
- Find some keyword or filename in directory.
grep -r keyword /home/ubuntu/-ris for searching recursively inside directotries- grep something inside file
grep keyword file.txt- Search case insensitive
grep -i keyword file.txt-istands for case insensitive, by default grep is case sensitive.AWK:
- Find
TRACEfrom log and print column 1,2,5
awk '/TRACE/ {print $1,$2,$5}' errors.log- Get the exact line number
awk '/TRACE/ {print NR,$1,$2,$5}' errors.log- User condition using
NR=> row number
awk 'NR>=1 && NR<=20 && /TRACE/ {print NR,$1,$2,$5}' errors.log- Find
Find:
Find files with specific extension
find *.txtFind files in some directory with specific ending
find dir/ *.logFind files by a particular owner
find dir/ -user ubuntuFind files by a particular group
find dir/ -group devops
SSH:
Keys:
- Public key (id_rsa.pub)
private key (id_rsa)
Public key must be known by the server where you want to connect, and you must also have private key to connect.
Create keys:
ssh-keygenKeys are stored in
~/.ssh/directory.Connect using keys:
Permission must be 400
chmod 400 key.pemconnect
ssh -i /path/to/key.pem user@ipaddress- Types
yeswhen asked.
scp from host system to server
scp -i "key.pem" file.txt user@ipadd:/home/user/file.txtscp from server to our host system
scp -i "key.pem" user@ipadd:/home/user/file .
Systemctl
It is a Service controller, services like
docker,apache2,sshd,nginx, etc.Start any service
sudo systemctl start <service>Stop any service
sudo systemctl stop <service>Check status of any service
sudo systemctl status <service>