Lesson 03 - chad-p/wiki-linux-class GitHub Wiki
# Output the lines in the file that have the username in them
cat auth.log | grep <username>
# Match all lines that do not have the keyword (case insensitive) error.
cat syslog | grep -vi error
# Find all the processes that have firefox in them. Give me line numbers too.
ps aux | grep -in firefox
# Find out if 443 is a listening port
netstat -tlnp|grep LISTEN|grep :443
# Search in all files in the current directory that have the username
grep -i <username> *
# Find lines that start with "d". This would return directories. (you can do this with just ls too)
ls โal | grep โ^dโ
cat /etc/passwd
awk -F ":" '{print $1 $6}' /etc/passwd
awk -F ":" '{print $1 " - " $6}' /etc/passwd
# sort
# Create file with months not in order.
echo -e "Feb\nDec\nMar\nOct\nMay\nJun\nNov\nAug\nSep\nApr\nJan\nJul" > months
# Does this sort as you expect?
cat months | sort
# This is better
cat months | sort -M
# cut
# Use cut to parse the IP
ip -c a | grep inet | grep brd | cut -d " " -f 6 | cut -d "/" -f 1
# Find groups user belongs to
groups
id
# Delete students group
groupdel students
# Create new group with GUID 101
groupadd -g 101 students
# Add group students to supplementary group of user
usermod -a -G students <user>
# Find out who is members of the sudo group
sudo groupmems -lg sudo
-
https://www.howtogeek.com/447906/how-to-control-sudo-access-on-linux/
-
visudo
-
sudo -l
Get info about my access -
sudo -i
same assudo su -
Logs into root
-
chmod
# Modify permissions -
chown
# Modify ownership
- https://tbhaxor.com/demystifying-suid-and-sgid-bits/
- https://www.redhat.com/sysadmin/suid-sgid-sticky-bit
touch myfile
chmod 4764 myfile
ls -l
-
find . -perm -6000
# Way to find files with suid or sgid set
# Create Hard Link
touch file
ln file hardfile
ll -i
echo "hello" >> file
cat hardfile
rm file
ll
rm hardfile
# Create Soft Link
ln -s file softfile
ll -i
rm file
ll
rm softfile