Home Random

GNU/Linux

This article was created in preparation for a job interview as SRE.

How would you connect to a machine in the cloud?#

What is does the directory /proc represent?#

/proc displays the current state of the kernel, inside the filesystem. This is possible because everything in linux is treated as a file.

How to find out the total disk usage?#

How to check for open ports?#

There are ways to find out the open ports of a system.

To find the process which opened the port you can use:

Check the version of kernel#

How to manage services#

How to check for cpu usage?#

Press h in top to get help.

top#

What filesystems are and which would you choose for which job#

Explain the filesystem hierarchy#

Find all mounted devices {#Find all mounted devices}#

What is a init-system?#

The standard init-system as for today is systemd. systemd is responsible for reparenting orphaned processes. To see which init-system a system runs, go into htop and search for PID 1. If the name of the binary does not already tell (cuz maybe its just says init), you can use file /sbin/init and see the output which would be /sbin/init: symbolic link to ../lib/systemd/systemd.

What is a process?#

A process is nothing but a executing binary. The multiple kind of processes:

What is a user?#

A user is just a few entry in some config-files:

There is a weird process. Find out things about it#

You can use top or htop to start the investigation. With PID and name you could also use ps aux. With lsof -p <PID> you could see, which files/sockets are opened by the process.

Please explain more about /proc#

In /proc you can see multiple directory named as numbers. These are processes. More about these things: https://linuxwiki.de/proc/pid

What are inodes?#

Inodes are metadata (filesize, read-write-date, permissions) in the linux filesystem. In some instances, inodes could occupy more space than the actual data stored on the system. To find out about inode-usage use df -i.

Difference between a process and a thread?#

A thread is a segment of process, which means: a process can hold multiple threads. Thread are less isolated, which means they share memory with other threads.

What command used to find processes as well as cpu and memory usage?#

For memory usage you can use free -h. For the cpu usage you could look at /proc/stat. For a nice summary top or htop would be good.

How to automize a repeating task?#

You could write script and give it to cron or on systemd-systems you could use a unit-file with a [Timer]-Section.

How to find a file?#

Usually I would use locate. It is faster than find because it does not search in realtime. But I also does not search in realtime. To update the cache/database locate is referring to, type sudo updatedb.

Examples of using find:

Networking#

For troubleshooting the network-connection. You should always have ip, dhcp and dns in mind.

Find out the mac-address of an interface#

How to get the ip-address of the interface eth0?#

Turn networking interface on/off#

> Have you tried to turning your device off and on again?

I case you do not get a ip-address

How to restrict access to a certain port?#

To directly restirct access, you would use the iptables-tool. With this tool you can configure rules for network connection. Because this tool itself is hard to handle (because of complexity), therefore there is a wrapper-tool called ufw for the home user.

# Drop everything accessing port 22
sudo iptables -A INPUT -p tcp --dport 22 -j DROP
# Accept <ip> on port 22
sudo iptables -A INPUT -p tcp --dport 22 -s <ip> -j ACCEPT

More about iptables on https://www.netfilter.org/

The successor of iptables is nftables.

Setting up a new interface#

Adding a new dummy interface for testing & simulation:

Change the ip-address for an interface#

How to find out which network-manager is in use right now?#

There is no other way than searching for all know managers.

Advanced Topics#

Filesystem#

Memory#

Processes#