General Notes with respect to this Lab Exercise
FAQ concerning Lab Work of Lehrgebiet Informationstechnische Systeme (ITS)
As the technical setup (using VirtualBox Virtual Machines) is similar in several of Prof. Classen’s lectures / labs, we provide shared FAQ answers in a separate, shared Ilias course at Support für die WF Praktika Prof. Claßen. Feel free to become a member of that Ilias course.
A Wiki there provides FAQ answers related to the technical setup of the Prof. Classen labs. New FAQ answers will be added on demand. If you have problems creating and starting the VM, first check the information in our FAQ. In particular, the points on the topic of activating hardware virtualization on Windows systems.
Specific questions specifically related to one module' lab only will however not be answered there, but in the Ilias of the specific module instead. Only questions that are valid for multiple / all of the labs will be handled via the shared Support Wiki.
On your own computer: VirtualBox Installation
VirtualBox Version 7.x is installed on the terminal computers.
If you are working on your own computer, so you should also install and use the latest version of Virtualbox 7.x.
Operating the VirtualBox VM
With VirtualBox, the mouse and keyboard may be "caught" in the VM,
as soon as you click in the console window.
You can then "release" it by pressing the right Ctrl key.
Persistence of data and changes
The changes in the virtual machine are persistent even if you have to shut down or reboot the virtual machine during the lab exercises.
Interrupting the Lab Work: Shut down the VM, do not pause it
If you need to interrupt your lab work, please do not pause the VM, instead, shut down the VM. Otherwise, when paused, the VM will not have a working network connection when you continue your work.
Superuser Permissions
Many of the commands and file content changes in the following exercises
require superuser (root) permissions, because they impact general system settings. In many cases, this is explicitly mentioned in the explanation of the respective exercise.
We do however expect you to understand the concept,
so therefore there might be cases where you are expected to recognize and handle this yourself.
As a general hint: should you get error messages like command not found or Permission denied
when issueing a command, this might be an indication
that the respective command needs to be executed as
root superuser.
Download and Setup of the Virtual Machine (VM) Users_Processes_VM
On the FH Aachen PCs:
Start VirtualBox.
Importing the appliance for the ITS-VM ("ITS" == "Lehrgebiet Informationstechnische Systeme, Prof. Claßen"):
Open the windows command shell cmd.exe by clicking on the menu in the bottom left corner, then "blindly" type in cmd, followed by a left click onto cmd.exe. Enter the following command into the shell:
1net use S: \\ad.fh-aachen.de\files\FB05\StudiShare
You should now see a new drive S: in the explorer.
=== Importing the appliance for the VM) Users_Processes_VM
In VirtualBox menu file :
import appliance, select ITS_Client_debian12_AMD64_V02.ova in
S:\Classen\VM_OVAs\ ,
click Next,
change name setting to Users_Processes_VM.
On FH terminal room computers:
change virtual disk image to
D:\VMs\Users_Processes_VM.vmdk.
|
Assign a new MAC address
Important (on all computers):
Make sure to set the checkbox
Assign new MAC addresses for all network cards,
alternatively go to MAC Address Policy
and set Include all network adapter MAC addresses.
|
Finally click on Import.
On your private computer:
Download ITS_Client_debian12_AMD64_V02.ova from
https://fh-aachen.sciebo.de/s/voHfcjRsXAfYbfJ
In VirtualBox menu file :
import appliance, select ITS_Client_debian12_AMD64_V02.ova
from your local download folder,
click Next,
change name setting to Users_Processes_VM.
|
Assign a new MAC address
Important (on all computers):
Make sure to set the checkbox
Assign new MAC addresses for all network cards,
alternatively go to MAC Address Policy
and set Include all network adapter MAC addresses.
|
Finally click on Import.
Starting the VM
Start the VM.
Should you get an error message when starting the VM regarding
VirtualBox Host-Only Ethernet Adapter is not a Host-Only Network
(or similar), the name of the host-only network in your VirtualBox installation differs from
the name expected by the VM definition.
For the VM refusing to start, click on Configure (upper-left of the
VirtualBox window) and a settings window will open for that VM.
Click on OK without changing any VM settings.
This will nevertheless update the VM settings and correct the problem.
Start the VM again.
Account Data for the VM
The user accounts of the VM are:
-
User:
itsadmin, Password:itsadmin -
Administrator-User:
root, Password:itsadmin
Result logging
To show that you have successfully finished this lab, please upload a log file to ILIAS. The log file will contain all commands that you typed in during your session and all system outputs.
It is not a problem if there are commands in the logfile that did not work on first try or were typed in wrong, we just want to see that at some point all the required commands were used correctly.
Open a terminal in the virtual
machine and start the logging by using the script command
(option -a means: append to file in case the file is non-empty
when the logging to file is started):
1script -a Linux-praktikum-04.log
The following output should appear:
1Script started, file is Linux-praktikum-04.log
From now on, please only use the console in which the logger is running, so that everything gets logged correctly!
If you want to interrupt the lab and shut down the virtual machine, e.g. to take a break, or if you get interrupted somehow, you have to restart the logging when you continue. Choose a new / different file name. Finally, use a text editor to merge the resulting log files into a single file in the correct order.
After completing the lab, upload the complete result files to the Ilias course.
User Management under Linux
Log into the VM:
User: itsadmin, password: itsadmin
Open a terminal window with a command line session, e.g. via the menu at the bottom left, menu item Terminal.
user identity
Enter the command whoami to determine the user identity under which you are currently working.
Enter the command id in order to determine the user identity under which you are currently working in another way.
Compare the output of the two commands. Note that the id command also provides you with the numeric user ID of the user.
You do not need to record the results of actions such as "… compare …" or "… analyze …" in any form, i.e. you do not have to "provide written evidence" that you also carried out these analyzes …
Change to the identity of the root user by entering
1su - root
Enter the password itsadmin of the` root` user.
Use the whoami command to determine whether / that the change of user identity was successful.
Enter the exit command to end the session as user` root`.
You return to the session as the original user. Check this out.
user switch is via command line session
Open a second terminal window with a second command line session, e.g. via the File menu,` New Tab` entry.
Give the command there
1su - root
and authenticate as root. Then enter id to check your user identity as` root` there.
By selecting the previous tab, switch to the first command line session that is still running and enter the id command there. Observe that the user change did not take place in the first session. This means that you are currently working under different user identities in the two command line sessions.
Use the second tab to switch back to the second command line session and enter the command exit there. This will switch you back to the identity of the itsadmin in this session; check this out. You are now working under the same user identity again in both sessions.
End the second session by entering the command exit there.
sudo
In the now only command line session, check under which user identity you are currently working and make sure that it is not the identity of the root user.
As a non-root user, try to update the list of installable software packages using the following command:
1apt-get update
Notice that you get permission denied error messages. The reason for this is that the package lists are classified as system configuration files and can therefore only be updated by the root user (as administrator user).
The sudo software is already installed on the lab VM. It is also configured in such a way that the itsadmin user can use` sudo` to execute any command under any user identity (i.e. also under the identity of the root user) without having to authenticate by entering a password.
Enter the whoami command again and then use the` sudo --user = root … command to execute the above command to update the package lists under the root` identity.
Then enter whoami again to determine that you are back in the original user identity after executing the` sudo` command, i.e. that the user change with sudo only takes place for the specified command.
If the sudo command does not specify a target user identity via` --user = … , root` is assumed as the target user. So enter the command again, but this time without specifying the target user:
1sudo apt-get update
Question (please answer this question yourself; answer does not have to be submitted): Why do the following two commands produce different outputs?
1
2
whoami
sudo whoami
useradd
Create a new user dummy1 using the following command:
1sudo useradd --create-home dummy1
Since creating a new user in the system is a system administration task, it can only be done by the root user. Therefore the useradd command must be executed under the identity of the` root` user, or the sudo command is used to execute exactly this command under the identity of the` root` user.
Set password
Set the password dummy1pw for the new user` dummy1` using the command …
1sudo passwd dummy1
... and by entering the new password twice.
The new user is now “ready to use”. Change to his user identity using the command …
1su – dummy1
... and entering his newly set password. Check that you are in fact now working under the new user’s identity.
Use the id command to find out the user ID of the new user. Make a note of this user ID.
Then create a new text file file1.txt with any content in the home directory` / home / dummy1` of this new user (you are probably located there anyway).
Let yourself be …
1ls -l /home/dummy1
... output the directory contents and make sure that the files there belong to user dummy1.
1
2
3
4
su – root
# ... dann das Passwort “itsadmin” des root Benutzers eingeben
sed -i "s/dummy1/willi/g" /etc/passwd
exit # ... wechselt zurück zum Benutzer dummy1 / willi
Renaming the new user
Use the following commands to change the user name in the central file / etc / passwd, in which the user IDs and user names are stored:
Let yourself be again by means of …
1ls -l /home/dummy1
... output the directory contents and make sure that the files there now belong to the user willi.
Only the user ID of the file owner was saved and this has not changed.
Also check under which user identity you are now working.
Note that the directory name of the home directory /home/dummy1 has not changed as a result of the renaming.
Undo the renaming (is important, otherwise deleting the user will not work properly because of the inconsistencies):
1
2
3
4
su – root
# ... dann das Passwort “itsadmin” des `root` Benutzers eingeben
sed -i "s/willi/dummy1/ g" /etc/passwd
exit # ... wechselt zurück zum Benutzer dummy1 / willi
Exit the new command line after these commands with exit. The new tab closes with it.
Check that you are working under the original user identity dummy1 in the first tab.
Leave the command line session under the new user identity using the exit command.
Check that you are working under the original user identity itsadmin again.
Delete the new user
Delete the new user by entering the command …
1sudo deluser --remove-home --quiet dummy1
Processes and Signaling
Use ps to display the processes of the current user that are connected to a terminal (input / output, i.e. keyboard and screen).
In a Bash command line, the variable $$ stores the process ID of this command line.
So use echo $$ to output the value of this variable and compare the process ID: s.
The pgrep command searches for all processes with a certain name and outputs their process ID: s.
So use pgrep bash to search for the process ID: s of all running command lines.
Open a second tab in the terminal and use pgrep bash to display the process ID: s of all Bash command lines.
Close the second tab with exit and enter the command` pgrep bash` one last time.
Display the list of all processes using ps aux.
Notice that there are now many more processes from this user listed.
Analyze under which user identities processes were started in the system.
Processes are arranged hierarchically in Bash: every process except for the init process has a parent process.
Use pstree to display the hierarchical structure of all processes.
If pstree is not installed: sudo apt install psmisc
|
Start an interactive Python interpreter with the command python3.
Open a second tab in the terminal and determine the process ID of this Python process there.
Send a signal to the process to terminate it (check that the process is terminated).
Then close the second tab again using exit.
Signal Processing, a bash script
Write a bash script which first outputs the current date and time in an endless loop (command date without parameters) and then always sleeps for 60 seconds (` sleep`).
Whenever Ctrl-C is pressed, the program should display` Thanks for pressing Ctrl-C` and exit.
Other signals should not be intercepted by the program.
signal processing, several bash scripts
Create two bash scripts child_one.sh and` child_two.sh`, which both execute a sleep 5 in an endless loop,
i.e. "sleep" again and again for 5 seconds at a time.
Furthermore, these scripts should have a signal handler that handles the TERM signal and then terminates the process with` exit`. Make both scripts executable.
Create another bash script parent.sh, which also executes a` sleep 5` in an endless loop and starts the two child scripts in the background before the loop is executed.
The parent script should also have a signal handler that handles the TERM signal and terminates the process with` exit`. Make this script executable too.
Start the parent script and check (in another command line) that all three scripts are running. Send the TERM signal to the parent script. It should end.
Check whether the child scripts are still running or not. If so, terminate the child scripts by sending the TERM signal to each of the child scripts as well.
Edit the parent script: The child scripts should no longer be started in the background, but in the foreground. Start the parent script and check (in another command line) which of the scripts are running.
Send the TERM signal to the parent script. What is happening? (please answer this question yourself; answer does not have to be submitted)
Send the TERM signal to all running child scripts (how many are there? ⇒ Please answer this question yourself; answer does not have to be submitted).
What happens to the child script and the parent script?
Upload of console log file and completion of this lab
When you have finalized your lab work, you need to end the logging by entering exit into your console. The following output should appear:
1Script done, file is Linux-praktikum-04.log
Start a webbrowser inside the virtual machine and upload the log file to ILIAS, using this web browser.
Shut down the VM, remove the VM completely (delete all files) and end your session.