Skip to content

damianposlowski/linuxupskillchallenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

These are my notes made while taking the linuxupskillchallenge. I used them to have a quick recap resource and to document my journey with the challenge. This repo will also include the accompanying bash scripts.

To take the challenge visit: https://www.reddit.com/r/linuxupskillchallenge/

Day 0
Setup a server (Ubuntu 20.04 (LTS) x64) on Digital Ocean
Create an admin account with:
$ adduser username
$ usermod -a -G adm username
$ usermod -a -G sudo username
Login to admin and update Ubuntu Linux system with:
$ sudo apt upgrade
$ sudo apt update

Day 1
Setup Xubuntu Virtual Machine in Oracle Virtual Box
Remote log into the server with:
$ ssh username@IPaddress
Check basic command (ls, uptime, free, df -h, uname -a)
Check for existing ssh keys with:
$ ls -al ~/.ssh/id_*.pub
Setup passwordless SSH login with:
$ ssh-keygen -t rsa -b 4096 -C "email@domain.com"
$ ssh-copy-id username@IPaddress
Show space and processes running with:
$ df -h
$ free -h
$ ps

Day 2
Test creating directories with:
$ mkdir test
Learn about pwd and ls with switches (ls -ltra), understand hidden files (starting with .)
Try moving around different directories with:
$ cd ./test/anotherTest
$ cd ../
$ cd ~
$ cd –
$ cd
$ pushd ./test
$ pushd ./anotherTest
$ popd
Learn about the full path and relative path to access the directory

Day 3
Learn about the sudo command
Learn about the cat and less commands (cat for string manipulation, less for file reading)
Reboot the system and checking uptime with:
$ sudo reboot
$ uptime
Enter and exit from the root user with:
$ sudo -i
$ exit
Rename the server and blocking the hostname change after reboot (using vim text editor) with:
$ sudo hostnamectl set-hostname myservername
$ sudo vi /etc/cloud/cloud.cfg
Change the value to "preserve_hostname: true" and save with ":x"
Check the timezone, filter by Europe and change to my current location with:
$ timedatectl
$ timedatectl list-timezones
$ timedatectl list-timezones | grep Europe
$ sudo timedatectl set-timezone Europe/Warsaw

Day 4
Try searching for different packages with:
$ apt search "package name"
Install a package with:
$ sudo apt install package name
Learn how to use the Midnight Commander app

Day 5
Use the more and less commands with:
$ more ../../var/log/auth.log
type "h" to see how to navigate
type "q" to quit
$ less ../../var/log/auth.log
type "h" to see how to navigate
type "g" to get to the beginning of the file
type "G" to get to the end of the file
type "/" to search
type "n" to see the next search result
type "N" to see the previous search result
type "q" to quit
Learn about the history command and repeating previous lines with:
$ history
$ !20
Use Ctrl + r to search for previous commands
Use nano to create a new file with:
$ nano test.txt
$ less test.txt

Day 6
Learn about vi/vim editor
Check the version with:
$ vi --version
Learn about the normal and insert mode:
"Press Esc twice or more to return to normal mode"
Copy a file to test vim with:
$ cp -v /etc/services testfile
$ vim testfile
Use "!q:" to quit without saving
Use the keys "h" "j" "k" and "l" to move around
In normal mode try deleting 33 lines with "33dd"
undo the changes with "u" or "ctrl + r"
Use "G" to get to the bottom of file
use "gg" to get to the top of the file
Find text, for example "sun" with "/sun", then use "n" to get the next result
Replace text with "%s/old/new/c" or for global "%s/old/new/gc"
Delete two lines with "2dd", then revert with "u"
Paste these lines somewhere with "p"
Cut character with "x" in normal mode and "delete" in insert mode and "d"or "x" in visual mode paste the character somewhere with "p"
Copy with "y", paste with "p"
Press "i" to start the insert mode and write some text
Press "v" to enter the visual mode
Use ":w" to write the changes to the file and ":wq" to save and quit
Use ":w filename" to save as a different file

Day 7
Refresh the available package list with:
$ sudo apt update
Install apache web server with:
$ sudo apt install apache2
Browse your sever IP to see if apache works
Stop apache web server with:
$ sudo systemctl stop apache2
Start apache web server with:
$ sudo systemctl start apache2
Check server status with:
$ systemctl status apache2
Check the apache configuration file with:
$ less /etc/apache2/apache2.conf
$ vim /etc/apache2/apache2.conf
Check the default webpage location with:
$ vim /etc/apache2/sites-enabled/000-default.conf
View code of the default page with:
$ vim /var/www/html/index.html
Edit code on the default page with:
$ sudo vim /var/www/html/index.html
"i" and add/edit code
use "ggVG" to select all (gg to move to the top, V to enter visual mode, G to select all till the end)
use "ggdG" to delete all (gg to move to the top, dG to delete everything till the end of file)
":qw" to save it and quit
Test your page by browsing the IP again
Check apache logs with:
$ cd /var/log/apache2
$ ls
$ less access.log
$ less error.log
Find a websites IP address with:
$ dig +short www.yourwebsitedomain.com
Check IP address with:
$ sudo apt install whois
$ whois IP address
Make sure the latest security updates are installed with:
$ sudo apt update
$ sudo apt upgrade

Day 8
Print something on the screen with:
$ echo text
View the file content with:
$ cat /var/log/apache2/access.log
$ less /var/log/apache2/access.log
Use reverse "tac" which is a reverse "cat", with:
$ tac /var/log/apache2/access.log
Practice "less" controls (g, G, /, n, N)
Search for sudo uses with:
$ less /var/log/auth.log
Search with "/" then "n" for next line
Look at beginning and end of a file with:
$ head /var/log/apache2/access.log
$ tail /var/log/apache2/access.log
$ head -5 /var/log/apache2/access.log
Follow a log in real time with:
$ tail -f /var/log/apache2/access.log
Count the number of lines, words or characters with:
$ wc file.txt
$ wc -l file.txt
$ wc -wc file.txt
Try using the pipe "|" symbol with cat and grep (a filter command):
$ cat /var/log/auth.log | grep "authenticating"
Use simpler version with:
$ grep "authenticating" /var/log/auth.log
Pipe the simpler grep command with another filter with:
$ grep "authenticating" /var/log/auth.log | grep "root"
Filter grep results even further with the cut command, using -d (delimiter) and -f (field) with:
$ grep "authenticating" /var/log/auth.log| grep "root"| cut -f 10- -d" "
the delimiter is what separates the field (in this case " ", so empty space), and f says how many of
these fields should be cut ("-f 10-12" shows 3 fields, from 10 till 12)
Invert the search (filter out matching values) using "-v" with:
$ grep "authenticating" /var/log/auth.log | grep -v "root"| cut -f 10- -d" "
The above shows login attempts from other users than root
Save results to file with:
$ ls -ltr > listing.txt
$ grep "authenticating" /var/log/auth.log| grep -v "root"| cut -f 10- -d" " > ~/attackers.txt
Append a file with:
$ echo "text at the bottom" >> file.txt
Select just the unique and sorted IP addresses of attackers with:
$ grep "authenticating" /var/log/auth.log| grep -v "root"| rev | cut -f4 -d" " | rev | sort | uniq
Try regular expression to get the IP addresses with:
$ grep "authenticating" /var/log/auth.log| grep -v "root"| grep -o "[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}" | sort | uniq
Try "awk" and "sed" with:
$ ls -l | awk ‘{print $3}’
above prints the 3rd column from the list of files
$ awk '{print $1,$4}' file1.txt
above prints the first and forth word from the file
$ awk '{print NR, $1,$4}' file1.txt
above adds a line number to the print
$ sed -n ‘/hello/p’ file1.txt
above prints all the lines with "hello"
$ sed ‘s/hello/HELLO/’ file1.txt
above replaces "hello" with "HELLO"
$ sed ‘/hello/,+2d’ file1.txt
above deletes the first two lines with "hello"

Day 9
Check open ports with:
$ sudo systemctl start apache2
$ ss -ltpn
ports 80 and 22 open "to the world" on all local IP addresses - and port 53 (DNS) open only on a special local address
Scan your server with:
$ sudo apt install nmap
$ nmap localhost
$ nmap 127.0.0.1
port 80 (http) is for Apache (open when Apache is running), port 22 (ssh) is how your connected to the cloud server (open all the time, when server is running)
Find exposed IP addresses:
$ ip a
above lists all IP addresses of your network card
$ nmap 104.253.14.92
above scans the IP address
$ nmap localhost
above scans your server
Check firewall rules with:
$ sudo iptables -L
policy ACCEPT means that there is no firewalling – all traffic is accepted
Use the "uncomplicated firewall" command with:
$ sudo apt install ufw
$ sudo ufw allow ssh
$ sudo ufw deny http
$ sudo ufw enable
$ sudo iptables -L | grep "http"
now all the incoming traffic to port 80/http is dropped
Revert the above with:
$ sudo ufw allow http
$ sudo ufw enable
Check the status with:
$ sudo ufw status
Disable firewall with:
$ sudo ufw disable

Day 10
Learn about task scheduling
Check the scheduled tasks for logged user and the root user with:
$ crontab -l
$ sudo crontab -l
Check the system-wide crontab with:
$ less /etc/crontab
Check system-wide scheduled tasks with:
$ ls /etc/cron.*
$ ls /etc/cron.daily
Listed tasks run in alphabetical order
Add tasks in the crontab file with:
$ sudo vim /etc/crontab
"30 10 * * * root echo $(date) "Message text" >> /home/folder-name/cron-messages"

above ads message every day at 10.30
"@reeboot root echo $(date) "Reboot text" >> /home/ folder-name /cron-messages"
above ads message at every reboot
Learn about "at" and "anacron" commands:
- at - schedules task only once
- anacron - can schedule tasks with frequency defined in days, but does not drop a task when the machine is turned off (instead it will run the task when you power on your machine)
- cron - can schedule tasks with frequency of minutes, but drops a task if server if offline
Learn about "logrotate" and check the current rotation with:
$ ls /etc/logrotate.*
Check the system timers with:
$ systemctl list-timers

Day 11
Learn how to find files and file content with locate, find, grep, which
Use locate to search for files with:
$ sudo apt install mlocate
$ locate access.log
$ sudo updated
above updates index of recent files (the index is updated nightly by cron)
Use find (slower than locate because it searches the filesystem not index) to search for files with:
$ find /var -name access.log
above searches for access.log in /var
$ find /home -mtime -3
above searches for all files in /home modified in the last 3 days
$ find /var -name access.log 2>&1 | grep -vi "Permission denied"
above filters out files without permission (you could also use sudo with the find command)
Use grep -R to search for files with:
$ grep -R -i "PermitRootLogin" /etc/*
above searches for files containing "PermitRootLogin" in /etc (-i makes the search case insensitive)
To search for compressed files use zgrep (and to view them use zless)
Search for command location (where is it run from) with:
$ echo $PATH
above shows all locations in your path
$ which nano
$ which grep
$ which vim
$ which reboot

Day 12
Learn about sending files between your local machine and the server
Use SFTP (SSH File Transfer Protocol) to move files with:
$ sftp -i "keypair file" user@serverIP
Check the keypair file run the below:
$ cd ~/.ssh/
Check files and directories with:
$ pwd
shows that it’s a remote directory
$ lpwd
shows local directory
$ ls
lists remote directory files
$ lls
lists local directory files
Transfer files with:
$ put ./Desktop/file.txt
above copies the file from local to remote directory
$ get server-file.txt
above downloads the file from remote to local directory
$ mput file
above copies all the files with "file" ending, to the remote directory
$ mget another

above downloads all the files starting with "another" to your local directory
$ exit

Day 13
Check files ownership with:
$ ls -l
Above shows permission for r (read), w (write) and x (execute/run) for three categories of users:
- owner
- group
- others
Create a file and add some text with:
$ vim test.txt
Check permissions with:
$ ls -l
Remove writing permission from user and group, and reading permissions from others with:
$ chmod u-w test.txt
$ chmod g-w test.txt
$ chmod o-r test.txt
$ vim test.txt
Add back permissions to edit with:
$ chmod u+w test.txt
Check your groups with:
$ groups
Add new user or add user to a group with:
$ adduser fred
$ usermod -a -G group user
Change user and check groups with:
$ sudo su fred
$ groups
$ exit

Day 14
Check disk space with:
$ df -h
Create new user with:
$ sudo adduser bob
$ sudo passwd bob
Check added users with:
$ less /etc/passwd
$ less /etc/group
$ sudo less /etc/shadow
above shows hashed password
$ ls ./../
above shows created home directories
$ getent group {1000..6000}
above shows only "non system" users
$ groups mainuser bob
above shows listed user groups
$ sudo su bob
Try rebooting with:
$ reboot
$ sudo reboot
Check the file defining the root/sudo privileges with:
$ sudo less /etc/sudoers
Change users permission to allow sudo reboot with:
$ sudo -i
$ visudo
Add the below lines to the file:
# Allow user "bob" to run "sudo reboot"
# ...and don't prompt for a password
#
bob ALL = NOPASSWD:/sbin/reboot
Check the changes with:
$ sudo su bob
$ whoami
above shows current shell/user
$ sudo reboot
Change username and groupname with:
$ sudo usermod -l newname bob
$ sudo groupmod -n newname oldname

Day 15
View URLs of repositories for the packages (apps) you can install with:
$ less /etc/apt/sources.list
you can uncomment universe, multiverse and partner repository lines from this file to allow additional package installation (for example non-open source)
Add additional repositories via command line with:
$ sudo add-apt-repository universe
$ sudo apt update
$ sudo apt upgrade
Check the list of packages you can install with:
$ apt-cache dump
click "ctrl + c" to exit
$ apt-cache dump | grep "Package:" | wc -l
above shows the number of packages you can install (grep filters to show only lines with package name and "wc -l" counts lines)
Check information about an installed package with:
$ sudo apt-cache show apache2
$ sudo apt-cache depends apache2
above shows dependancies (packages that need to be installed for it to work)
$ sudo apt-cache rdepends apache2
above shows packages that depends on this one to work properly
Install "neofetch" to view your configuration and hardware with:
$ sudo apt install neofetch
$ neofetch
$ neofetch --version
Instal PPA (Personal Package Archive) to get unofficial/new/personal software with:
$ sudo add-apt-repository ppa:dawidd0811/neofetch
$ sudo apt update
$ sudo apt install neofetch
$ neofetch --version
Remove a package with:
$ sudo apt autoremove packagename

Day 16
Create a snapshot of current files with:
$ tar -cvf myinits.tar /etc/init.d/
$ tar -cvf test.tar /./test-folder/
Compress the tar file to create a "tarball" (.tar.gz format) with:
$ gzip myinits.tar
$ gzip test.tar
Compress the files in one step (.tgz format) with:
$ tar -cvzf myinits.tgz /etc/init.d/
in the above, -c means that you are creating an archive (snapshot), -v is giving feedback (making the command verbose), -z is compressing the files and -f lets you specify the file output (for example test.tar)
Check file sizes with:
$ ls -lh
$ du -h myinits.tgz
above checks specific file (ls shows all in the current directory)
Untar/unpack .tar and .tar.gz and .tgz files using -x with:
$ tar -xvf test.tar
$ tar -xvf test.tar -C /./test-folder/
above lets you select a folder where to untar the files
Check .tar and .tar.gz and .tgz content using -t with:
$ tar -tvf test.tar
$ tar -tvf test.tar.gz
$ tar -tvf test.tgz
Using gzip to compress and uncompress files with:
$ gzip file-name
$ gunzip file-name.gz

Day 17
Install the standard bundle of common compilers with:
$ sudo apt install build-essential
Use the latest version of nmap with:
$ nmap -V
$ which nmap
above shows where the executable is stored
$ wget -v https://nmap.org/dist/nmap-7.93.tar.bz2
above downloads the latest 7.93 version
$ tar -jxvf nmap-7.70.tar.bz2
in the above -j uncompress, -x extracts, -v gives feedback and -f lets you specify the file name
Check the files with:
$ ls -ltr
$ mc nmap-7.93/
$ cd nmap-7.93/
$ less README.md
Install the nmap with:
$ less INSTALL
above gives you instruction on what installation commands to use
$ ./configure
$ make
$ sudo make install
Update the index of files and search for nmap with:
$ sudo updated
$ locate bin/nmap
you will see both the original (/usr/bin/) and new version (/usr/local/bin/)
Check versions with:
$ /usr/bin/nmap -V
$ /usr/local/bin/nmap -V
Execute nmap with:
$ ./usr/local/bin/nmap ipaddress
$ ./usr/local/bin/nmap-7.93/nmap localhost
new version
$ ./usr/bin/nmap-7.93/nmap localhost
old (original) version

Day 18
Learn about the logrotate app
Check logs with:
$ cd /var/log/
$ ls
Check the current log rotation with:
$ cd /etc/cron.daily/
$ cat /etc/logrotate.conf
$ cat /etc/logrotate.d/apache2
You can change the above file to change log rotation for apache
Check what was happening on the server since boot with:
$ journalctl -b
$ journalctl --priority=3
above will show all login attempts
$ journalctl --priority=1
above shows all the critical logs/errors
$ journalctl --since today
above shows what happened today
$ journalctl -f
above shows what is happening in the "live" mode

Day 19
Learn about the Linux Virtual Filesystem
View inode (index node), the layer between file name and the data on the disk with:
$ ls -li
$ ls -i text.txt
$ stat test.txt
the filename points to an inode, and the inode points to data on disk (inode example: 35356766)
Create a "hard link" in your home directory with:
$ cd
$ ln /etc/passwd link1
Create a "symbolic link" with:
$ ln -s /etc/passwd link2
Check the link files with:
$ ls -li
$ cat link1
$ cat link2
Check stats for the link and for the file it links to with:
$ stat link2
$ stat -L link2
the second one shows stats of the file the link is pointing to (this makes sense only for symbolic links, because hard link have the same inode/data as the file it’s linking to, so -L makes no difference)
Check directory with "symlinks" (symbolic links), to scripts that start when your machine changes to normal running state (runlevel 2) with:
$ ls -ltr /etc/rc2.d/*
Learn about the different between these link:
1) Hard links:
- Only link to a file, not a directory
- Can't reference a file on a different disk/volume
- Links will reference a file even if it is moved
- Links reference inode/physical locations on the disk
2) Symbolic (soft) links:
- Can link to directories
- Can reference a file/folder on a different hard disk/volume
- Links remain if the original file is deleted
- Links will NOT reference the file anymore if it is moved
- Links reference abstract filenames/directories and NOT physical locations.
- They have their own inode
Create an alias to have an easier way to reference a command with:
$ sudo apt install cowsay
$ cowsay moo
$ alias moo="cowsay moo"
$ moo
$ alias name="your command"
$ name

Day 20
Create a bash script with:
$ vim test.sh
Add "shebang" at the beginning of the script: #!/bin/bash
The above is an interpreter for your script (in this case bash)
Make the script executable with:
$ chmod +x test.sh
Execute the script with:
$ ~/scripts/test.sh
or
$ cd scripts/
$ ./test.sh
Move the script to somewhere on your $PATH with:
$ echo $PATH
$ sudo mv test.sh /usr/local/bin/test.sh
Run the script just using its name (possible because it’s on your $PATH), with:
$ test.sh
Create variables for referencing or use built-in variables in your script with, with:
$ LOG="/var/log/auth.log"
$ my_name="Bob"
$ echo "hello $my_name, you are using $LOG"
Use positional parameters provided when running the script, with:
script: echo "Hi $1, how are things going in $2?"
$ printing-script.sh Bob Canada
Above will produce: "Hi Bob, how are things going in Canada?"
Make a parameter mandatory with:
if [ -z $1 ]
then
echo "Usage is $0 "
exit 0
fi

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages