top of page
  • Linkedin
  • bluesky
  • Instagram

Notes: Linux Fundamentals Part 3 | THM

  • solbergtonje
  • 31 dec. 2024
  • 4 min läsning

Terminal Text Editors


Nano

Create/Edit file (launch Nano): nano FILENAME


Navigate in Nano: up/down arrow keys

Start new line: ENTER key


Features:

- searching for text

- copy/paste

- jumping to a line

- finding out what line number you are on


(use CTRL key (=^ on Linux) + letter. ex: CTRL + X = exit nano)


VIM

- customisable: modify keyboard shortcuts

- syntax highlight: useful writing/maintaining code

- works on all terminals where nano may not be installed

- lots of resources, like cheatsheets, tutorials etc

(THM Room: https://tryhackme.com/r/room/toolboxvim)



General/Useful Utilities


Downloading Files


Command: wget

- download files via HTTP

- needed: adr of resource


Ex: wget https://assets.tryhackme.com/additional/linux-fundamentals/part3/myfile.txt


Transferring Files From Your Host - SCP (SSH)


Secure Copy (SCP)

- allow transfer of files between two machines using SSH protocol <- provide authentication and encryption

- needed: credentials on both machines, IP adr of remote machine, name of file/folder

- command format SOURCE and DESTINATION


Copy file from local machine to remote machine

The IP address of the remote system: 192.168.1.30

User on the remote system: ubuntu

Name of the file on the local system: important.txt

Name that we wish to store the file as on the remote system: transferred.txt


Ex: scp important.txt ubuntu@192.168.1.30:/home/ubuntu/transferred.txt


Copy file from remote machine to local machine

IP address of the remote system: 192.168.1.30

User on the remote system: ubuntu

Name of the file on the remote system: documents.txt

Name that we wish to store the file as on our system: notes.txt


Ex: scp ubuntu@192.168.1.30:/home/ubuntu/documents.txt notes.txt


Serving Files From Your Host - WEB


Ubuntu comes with python3 <- provides a lightweight module HTTPServer <- turns machine into a web server <- store files <- other machines can download files using commands like curl and wget


Python3's HTTPServer

- store files in the directory where you run the command (can be changes, see man page)

- start the module with command: python3 -m http.server

- will run in Terminal until you cancel it

- disadvantage: need to know exact name and location of the file to download



Processes 101


Processes

- programs running on your machine

- managed by the kernel

- each process have an unique ID = PID

- PID increments for order in which the process starts (ex: 60th process -> PID 60)


Viewing Processes


Command: ps

- list running processes, user session


Command: ps aux

- list running processes of all users


Command: top

- listing processes in real-time (refresh every 10s)


Managing Processes


Terminate processes

Command: kill

Ex: kill PID_NUMBER


Command: sigterm

Ex: sigterm PID_NUMBER

- some cleanup tasks before terminating process


Command: sigkill

Ex: sigkill PID_NUMBER

- no cleanup before terminating process


Command: sigstop

Ex: sigstop PID_NUMBER

- stop/suspend process


How do Processes Start?


Namespaces

- OS use namespaces to split up resources (cpu, ram, priority processes) available

- great for security - isolation (only those in same namespace see each other)


PID 0

- process started when system boots

- system's init -> systemd

Any progr started - child process of systemd (systemd under COMMAND)


Getting Processes/Services to Start on Boot

(fex: web servers, database servers, file transfer servers)


Command: systemctl

- formatting: systemctl [option] [service]

- allows us to interact with systemd process/daemon


Start Apache

systemctl start apache2


Four options:

- start

- stop

- enable

- disable


An introduction to Backgrounding and Foregrounding in Linux

- process can run in two states: background and foreground

- good to put commands to work in background to be able to continue working in the Terminal

- send to background: & operator (ex: echo "Hi THM" & [1] 16889)

- CTRL + Z to background a process


Foregrounding a process

- see what's running, command: ps aux

- bring process to foregroun, command: fg



Maintaining Your System: Automation


Scheduling: cron

Interact with: crontabs

Crontabs: started during boot, facilitating/managing cron jobs


A crontab = a special file

- formatting recognised by the cron process - execute each line step-by-step

- Crontab support wildcard * (used when we don't provide a specific value)

- crontabs edited with: crontab -e (select editor to edit the crontab)


Crontabs require 6 specific values:

- MIN (minute to execute at)

- HOUR (hour to execute at)

- DOM (day of month to execute at)

- MON (month of year to execute at)

- DOW (day of week to execute at)

- CMD (command to execute)


Backup files every 12 hour:

0 */12 * * * cp -R /home/cmnatic/Documents /var/backups/


Crontqab Guru: https://crontab.guru/



Maintaining Your System: Package Management


Introducing Packages & Software Repos

- developers submit software to community to an apt-repository

- etc/apt (see content: ls, open file (sources.list): cat)

- add repositories: add-apt-repository


Managing Your Repositories (Adding and Removing)

- add repositories: add-apt-repository


Download GPG key (safety check) for Sublime Text 3 & use apt-key to trust it: wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -


Add Sublime Text 3's repository to apt sources list (best practice to have a separate file for every different community/3rd party repository)

- create file in /etc/apt/sources.list.d: touch sublime-text.list

- add Sublime Text 3 repository into the new file using Nano or other text editor

- update apt to recognise this new entry: apt update

- install software: apt install sublime-text


Remove packages: add-apt-repository --remove ppa:PPA_NAME/ppa

(or manually delete the new file created)

- apt remove [SOFTWARE_NAME] (ex: apt remove sublime-text)



Maintaining Your System: Logs


Log Files

- /var/log/

- contain logging info for applications and services running on system

- OS automatically manage these logs in a process knows as "rotating"


Fail2ban services (monitor attempted brute forces)

UFW services (firewall)


Logs of interest to monitor health of system and protecting it:

- access log

- error log

Contact / Kontaktformulär

© 2024-2025 Tonje Solberg

bottom of page