# 1.2 Linux advanced strand

<span style="font-weight: bold;">Advanced strand: </span> from <span style="font-style: italic;">“running commands”</span> → <span style="font-style: italic;">“thinking like a system admin / engineer”</span>

1. internal vs. global dns
2. NAT outbound and inbound port forwarding
3. private addresses
4. look in known\_hosts file, repairs
5. why MTM warnings matter
6. mulit-hop remote access (cuckoo’s egg situation)
7. scp
8. processes, kill -9
9. ps aux \| grep blah. (pipes)
10. absolute vs. relative paths
11. wildcards
12. file permissions, ownership
13. chmod
14. ls -la
15. editing config files
16. reading logs
17. shell scripts
18. making scripts executable
19. crontab -e
20. updating, upgrading, dpkg
21. systemctl start, stop, status
22. ufw status

<div id="bkmrk--1">  
</div><div id="bkmrk-private-addresses%3Aan"><div><div><span style="font-weight: bold;">Private addresses:</span></div></div><div>

- any machine on the internal network likely has a "fake" address in the form of 192.168.x.y, or 10.x.y.x, or in some rare cases 172.16.x.y (nobody uses this believe me)
- why? look this up
- compare the IP4 address for the elab-wiki server (see below) to the IP6 address
- many machines can also be reached by elab.local for example, with no DNS involved
- challege: look up the default network configuration for several commercial routers: what do you notice?

</div></div><span id="bkmrk-internal-vs.-global--1" style="font-weight: bold;">Internal vs. global DNS</span><div id="bkmrk-for-internal-network">

- for internal network users, you can run an internal DNS that resolves names to numbers
- test this by using NSLOOKUP to look up the elab.hpa.edu server
- change the DNS lookup server by typing <span style="font-weight: bold;">server 8.8.8.8 </span>
- repeat the command and compare
- challenge: repeat this process for elab-wiki.hpa.edu and xserve.hpa.edu

<div><span style="font-weight: bold;">NAT outbound</span></div></div><div id="bkmrk-when-you-browse-the-">

- when you browse the internet, there must be a way to convert your 192.168.x.y address into something else that the web servers can recognize
- this is done through network address translation or NAT outbound, where your address is translated into the address of your router on the way out
- this router is what the servers see
- this process is reversed on the way back in, sending the web page back to your protected internal machine

<div><span style="font-weight: bold;">Inbound port mapping-firewalls</span></div>

- the reverse of this is inbound port mapping, where an outside user contacts your router and is pointed to your internal machine, usually on a defined port, for example to run a game or host a web page
- challenge: look at the page below and describe how outside users might see the elab-wiki server:

<div><figure>![Screenshot 2026-03-31 at 1.01.03 PM.png](https://bookstack.kamuela.org/uploads/images/gallery/2026-09/mYABUNeXTQBu7j6S-screenshot-2026-03-31-at-1-01-03-pm-uxh9jrih.png)<figcaption>Screenshot 2026-03-31 at 1.01.03 PM.png</figcaption></figure>  
<span style="font-weight: bold;">SSH issues:</span></div></div><div id="bkmrk-when-you-establish-a">

- when you establish a secure shell connection, two things are added: one to your machine, the other to the host machine.
- in your machine, a host file is where these are stored, listing the IP address of the host and a key that the host has shared with you
- if the IP address of the host changes, you will be faced with a serious message in the terminal that such a host cannot be trusted
- to solve this, you must find the .known\_hosts file on your computer, open the file with nano, and delete the previous IP address + key line
- in practice, you could just erase the entire file, but any connection you have setup before this will have to be re-established
- challenge: find the .known\_hosts file on your mac and copy a line from it
- challenge: do the same with the pi

<div><span style="font-weight: bold;">Man in the middle attack (MTM):</span></div></div><div id="bkmrk-it-is-possible-for-a">

- it is possible for a hacker or bot to watch the network you are on, and masquerade as the host you are sharing a key with
- first they watch the keys being transferred, and copy these
- they then kick the host off the network (usually a wireless attack)
- they then use the key to interact with your computer, posing as the host
- MTM warnings check the .known\_hosts file and if the IP address does not match, it refuses to connect
- challenge: ssh into the control computer, then change the IP on the computer and repeat
- explain why an MTM warning matters

<div><span style="font-weight: bold;">Multi-hop remote access:</span></div></div><div id="bkmrk-ssh-into-one-of-the-">

- ssh into one of the pi units in the lab
- from that machine, login to another machine
- create a text file in this machine, on the Desktop
- enter some text and ctrl-o, return, then ctrl-x
- look up "the cuckoo's nest" by Cliff Stoll
- explain how the hacker was tracked and what was the resolution

<div><span style="font-weight: bold;">Secure copy: </span></div></div><div id="bkmrk-on-your-pi%2C-create-a">

- on your pi, create a text file called "payload" in your home directory: /home/pi using nano
- secure copy this file over to another computer using this command: scp /home/pi/payload pi@10.14.84.20:/home/pi
- go to that machine via ssh and verify that the file has been transferred
- verify from the GUI as well

<div><span style="font-weight: bold;">processes, kill -9</span></div></div><div id="bkmrk-type-ps--aux-to-see-">

- type ps -aux to see a list of processes
- open some app on your pi
- look again at the ps command result
- kill the process by using the kill -9 &lt;process ID&gt;
- n.b. be careful with kill -9 it is like an assassination: it kills with no warning, and no mercy

<div><span style="font-weight: bold;">processes, pipes</span></div></div><div id="bkmrk-let%27s-say-you-are-lo">

- let's say you are looking for a process, but can't find it
- piping means sending the result of one command to another like this: <span style="font-weight: bold;">ps aux \| grep blah</span>
- this means: "show me all processes and when you get that list grep (search) for the process called blah"
- try this out with the example above

<div><span style="font-weight: bold;">files, wildcards</span></div></div><div id="bkmrk-let%27s-say-i-want-to-">

- let's say I want to edit the file awesome in the home directory
- I could type sudo nano awesome
- or, since I am almost as lazy (faul) as a mathematician, I use: sudo nano awe\*
- this only works if there are no other files in that directory starting with awe, so use this with caution

<div><span style="font-weight: bold;">files, listing files</span></div></div><div id="bkmrk-the-ls-command-for-l">

- the ls command for list is something you will use constantly
- it is a summary, to see more, use the ls -la flag:
- l means long form, or all of the data
- a means all of the files, even the hidden ones
- challenge: use the ls -la command on your directory, what do you see?
- sudo nano .herobrine in your /home/pi directory
- enter some text and ctrl-o, return, then ctrl-x
- use ls on your directory
- look in the GUI for the file, where is it?
- repeat with ls -la
- create a hidden file on a remote machine then challenge the user to find the file

<div>files, who owns what?</div></div><div id="bkmrk-in-your-%2Fhome%2Fpi-dir">

- in your /home/pi directory, using ls -la you notice lots of other stuff like this:

<div><figure>![Screenshot 2026-03-31 at 1.36.13 PM.png](https://bookstack.kamuela.org/uploads/images/gallery/2026-09/TfB5hWx4vbbVrEgm-screenshot-2026-03-31-at-1-36-13-pm-cwrnfjhl.png)<figcaption>Screenshot 2026-03-31 at 1.36.13 PM.png</figcaption></figure></div></div><div id="bkmrk-what-does-all-this-m">what does all this mean?</div><div id="bkmrk-d-means-directory-or">

- d means directory or folder
- there are then three sets of three letters: r means read, w means write, x means execute
- these are for three levels of ownership: owner, user, everyone
- read counts at 1, write counts as 2 and execute counts as 4 (notice how these are all base 2 numbers)
- we could say a file you could read, write and run as a program was rwx or we could add these to make 7 (1+2+4)
- chmod is how we change the permissions on a file, so <span style="font-weight: bold;">chmod 777 </span>is the same as <span style="font-weight: bold;">chmod rwx</span>
- this would be dangerous, as you have made the file read write and execute for owner, user and everyone
- you may create a python program you want to run, so you would enter <span style="font-weight: bold;">chmod +x program.py</span>
- this makes the file a program that can be executed
- challenge: create a text file and notice the permissions
- <span style="font-weight: bold;">cd /var/www/html </span>and notice the permissions on index.html, the home page for your computer
- on the browser, go to 127.0.0.1 (me myself and I in computer language)
- sudo nano the index.html file and add some words after "It works"
- <span style="font-weight: bold;">ctrl-o, return, ctrl-x</span>
- re-visit the home page
- how could you do this as a remote user?

<div><span style="font-weight: bold;">files, installing packages</span></div></div><div id="bkmrk-while-most-apps-can-">

- while most apps can be installed using sudo apt get &lt;program name&gt; there are others that download into your computer, usually in the /home/pi/Downloads folder
- to open these, use this command: dpkg -i &lt;filename&gt;
- you might also look at pi-apps, which is an alternate file download project
- to update your computer, use <span style="font-weight: bold;">sudo apt upgrade</span>
- to upgrade, always add the -y flag: <span style="font-weight: bold;">sudo apt upgrade -y</span>

</div>---

<small>Migrated from Apple Server Wiki. Original page ID: T557x3</small>