updates the linuxfun ex
This commit is contained in:
parent
50dcad0a9b
commit
f799c3b552
|
@ -10,16 +10,16 @@
|
||||||
4. Read the man page of `rm`, make sure you understand the `-i` option of rm. Create and remove a file to test the -i option.
|
4. Read the man page of `rm`, make sure you understand the `-i` option of rm. Create and remove a file to test the -i option.
|
||||||
5. Execute: `alias rm='rm -i'` . Test your alias with a test file. Does this work as expected?
|
5. Execute: `alias rm='rm -i'` . Test your alias with a test file. Does this work as expected?
|
||||||
6. List all current aliases.
|
6. List all current aliases.
|
||||||
7a. Create an alias called `city` that echoes your hometown.
|
7. Create an alias called `city` that echoes your hometown.
|
||||||
7b. Use your alias to test that it works.
|
7. Use your alias to test that it works.
|
||||||
8. Execute `set -x` to display shell expansion for every command.
|
8. Execute `set -x` to display shell expansion for every command.
|
||||||
9. Test the functionality of `set -x` by executing your city and rm aliases.
|
9. Test the functionality of `set -x` by executing your city and rm aliases.
|
||||||
10 Execute `set +x` to stop displaying shell expansion.
|
10. Execute `set +x` to stop displaying shell expansion.
|
||||||
11. Remove your city alias.
|
11. Remove your city alias.
|
||||||
12. What is the location of the `cat` and the `passwd` commands?
|
12. What is the location of the `cat` and the `passwd` commands?
|
||||||
13. Explain the difference between the following commands:
|
13. Explain the difference between the following commands:
|
||||||
* `echo`
|
* `echo`
|
||||||
* `/bin/echo `
|
* `/bin/echo `
|
||||||
14. Explain the difference between the following commands:
|
14. Explain the difference between the following commands:
|
||||||
* `echo Hello`
|
* `echo Hello`
|
||||||
* `echo -n Hello `
|
* `echo -n Hello `
|
||||||
|
@ -189,20 +189,22 @@
|
||||||
1. Write a script that receives four parameters, and outputs them in reverse order.
|
1. Write a script that receives four parameters, and outputs them in reverse order.
|
||||||
2. Write a script that receives two parameters (two filenames) and outputs whether those files exist.
|
2. Write a script that receives two parameters (two filenames) and outputs whether those files exist.
|
||||||
3. Write a script that asks for a filename. Verify existence of the file, then verify that you own the file, and whether it is writable. If not, then make it writable.
|
3. Write a script that asks for a filename. Verify existence of the file, then verify that you own the file, and whether it is writable. If not, then make it writable.
|
||||||
4. Make a configuration file for the previous script. Put a logging switch in the config file, logging means writing detailed output of everything the script does to a log file in /tmp.
|
4. Make a configuration file for the previous script. Put a logging switch in the config file, logging means writing detailed output of everything the script does to a log file in `/tmp`.
|
||||||
|
|
||||||
## 26.6. practice : more scripting
|
## 26.6. practice : more scripting
|
||||||
|
|
||||||
1. Write a script that asks for two numbers, and outputs the sum and product (as shown here).
|
1. Write a script that asks for two numbers, and outputs the sum and product (as shown here).
|
||||||
Enter a number: 5
|
```
|
||||||
Enter another number: 2
|
Enter a number: 5
|
||||||
|
Enter another number: 2
|
||||||
|
|
||||||
Sum: 5 + 2 = 7
|
Sum: 5 + 2 = 7
|
||||||
Product: 5 x 2 = 10
|
Product: 5 x 2 = 10
|
||||||
|
```
|
||||||
2. Improve the previous script to test that the numbers are between 1 and 100, exit with an error if necessary.
|
2. Improve the previous script to test that the numbers are between 1 and 100, exit with an error if necessary.
|
||||||
3. Improve the previous script to congratulate the user if the sum equals the product.
|
3. Improve the previous script to congratulate the user if the sum equals the product.
|
||||||
4. Write a script with a case insensitive case statement, using the shopt nocasematch option. The nocasematch option is reset to the value it had before the scripts started.
|
4. Write a script with a case insensitive case statement, using the shopt nocasematch option. The nocasematch option is reset to the value it had before the scripts started.
|
||||||
5. If time permits (or if you are waiting for other students to finish this practice), take a look at Linux system scripts in /etc/init.d and /etc/rc.d and try to understand them. Where does execution of a script start in /etc/init.d/samba ? There are also some hidden scripts in ~, we will discuss them later.
|
5. If time permits (or if you are waiting for other students to finish this practice), take a look at Linux system scripts in `/etc/init.d` and `/etc/rc.d` and try to understand them. Where does execution of a script start in `/etc/init.d/samba`? There are also some hidden scripts in `~`, we will discuss them later.
|
||||||
|
|
||||||
## 27.15. practice: introduction to users
|
## 27.15. practice: introduction to users
|
||||||
|
|
||||||
|
@ -210,37 +212,37 @@
|
||||||
2. Display a list of all logged on users.
|
2. Display a list of all logged on users.
|
||||||
3. Display a list of all logged on users including the command they are running at this very moment.
|
3. Display a list of all logged on users including the command they are running at this very moment.
|
||||||
4. Display your user name and your unique user identification (userid).
|
4. Display your user name and your unique user identification (userid).
|
||||||
5. Use su to switch to another user account (unless you are root, you will need the password of the other account). And get back to the previous account.
|
5. Use `su` to switch to another user account (unless you are root, you will need the password of the other account). And get back to the previous account.
|
||||||
6. Now use su - to switch to another user and notice the difference. Note that su - gets you into the home directory of Tania.
|
6. Now use `su -` to switch to another user and notice the difference. Note that `su -` gets you into the home directory of Tania.
|
||||||
7. Try to create a new user account (when using your normal user account). this should fail. (Details on adding user accounts are explained in the next chapter.)
|
7. Try to create a new user account (when using your normal user account). this should fail. (Details on adding user accounts are explained in the next chapter.)
|
||||||
8. Now try the same, but with sudo before your command.
|
8. Now try the same, but with `sudo` before your command.
|
||||||
|
|
||||||
## 28.13. practice: user management
|
## 28.13. practice: user management
|
||||||
|
|
||||||
1. Create a user account named serena, including a home directory and a description (or comment) that reads Serena Williams. Do all this in one single command.
|
1. Create a user account named serena, including a home directory and a description (or comment) that reads Serena Williams. Do all this in one single command.
|
||||||
2. Create a user named venus, including home directory, bash shell, a description that reads Venus Williams all in one single command.
|
2. Create a user named venus, including home directory, bash shell, a description that reads Venus Williams all in one single command.
|
||||||
3. Verify that both users have correct entries in /etc/passwd, /etc/shadow and /etc/group.
|
3. Verify that both users have correct entries in `/etc/passwd`, `/etc/shadow` and `/etc/group`.
|
||||||
4. Verify that their home directory was created.
|
4. Verify that their home directory was created.
|
||||||
5. Create a user named einstime with /bin/date as his default logon shell.
|
5. Create a user named einstime with `/bin/date` as his default logon shell.
|
||||||
7. What happens when you log on with the einstime user ? Can you think of a useful real world example for changing a user's login shell to an application ?
|
7. What happens when you log on with the einstime user ? Can you think of a useful real world example for changing a user's login shell to an application ?
|
||||||
8. Create a file named welcome.txt and make sure every new user will see this file in their home directory.
|
8. Create a file named `welcome.txt` and make sure every new user will see this file in their home directory.
|
||||||
9. Verify this setup by creating (and deleting) a test user account.
|
9. Verify this setup by creating (and deleting) a test user account.
|
||||||
10. Change the default login shell for the serena user to /bin/bash. Verify before and after you make this change.
|
10. Change the default login shell for the serena user to `/bin/bash`. Verify before and after you make this change.
|
||||||
|
|
||||||
## 29.10. practice: user passwords
|
## 29.10. practice: user passwords
|
||||||
|
|
||||||
1. Set the password for serena to hunter2.
|
1. Set the password for serena to hunter2.
|
||||||
2. Also set a password for venus and then lock the venus user account with usermod. Verify the locking in /etc/shadow before and after you lock it.
|
2. Also set a password for venus and then lock the venus user account with `usermod`. Verify the locking in `/etc/shadow` before and after you lock it.
|
||||||
3. Use passwd -d to disable the serena password. Verify the serena line in /etc/shadow before and after disabling.
|
3. Use `passwd -d` to disable the serena password. Verify the serena line in `/etc/shadow` before and after disabling.
|
||||||
4. What is the difference between locking a user account and disabling a user account's password like we just did with usermod -L and passwd -d?
|
4. What is the difference between locking a user account and disabling a user account's password like we just did with `usermod -L` and `passwd -d`?
|
||||||
5. Try changing the password of serena to serena as serena.
|
5. Try changing the password of serena to serena as serena.
|
||||||
6. Make sure serena has to change her password in 10 days.
|
6. Make sure serena has to change her password in 10 days.
|
||||||
7. Make sure every new user needs to change their password every 10 days.
|
7. Make sure every new user needs to change their password every 10 days.
|
||||||
8. Take a backup as root of /etc/shadow. Use vi to copy an encrypted hunter2 hash from venus to serena. Can serena now log on with hunter2 as a password ?
|
8. Take a backup as root of `/etc/shadow`. Use `vi` to copy an encrypted hunter2 hash from venus to serena. Can serena now log on with hunter2 as a password ?
|
||||||
9. Why use vipw instead of vi ? What could be the problem when using vi or vim ?
|
9. Why use `vipw` instead of `vi`? What could be the problem when using `vi` or `vim`?
|
||||||
10. Use chsh to list all shells (only works on RHEL/CentOS/Fedora), and compare to cat /etc/shells.
|
10. Use `chsh` to list all shells (only works on RHEL/CentOS/Fedora), and compare to `cat /etc/shells`.
|
||||||
11. Which useradd option allows you to name a home directory ?
|
11. Which `useradd` option allows you to name a home directory?
|
||||||
12. How can you see whether the password of user serena is locked or unlocked ? Give a solution with grep and a solution with passwd.
|
12. How can you see whether the password of user serena is locked or unlocked ? Give a solution with `grep` and a solution with `passwd`.
|
||||||
|
|
||||||
## 30.9. practice: user profiles
|
## 30.9. practice: user profiles
|
||||||
|
|
||||||
|
@ -249,55 +251,55 @@
|
||||||
3. Put a unique variable, alias and function in each of those files.
|
3. Put a unique variable, alias and function in each of those files.
|
||||||
4. Try several different ways to obtain a shell (su, su -, ssh, tmux, gnome-terminal, Ctrl- alt-F1, ...) and verify which of your custom variables, aliases and function are present in your environment.
|
4. Try several different ways to obtain a shell (su, su -, ssh, tmux, gnome-terminal, Ctrl- alt-F1, ...) and verify which of your custom variables, aliases and function are present in your environment.
|
||||||
5. Do you also know the order in which they are executed?
|
5. Do you also know the order in which they are executed?
|
||||||
6. When an application depends on a setting in $HOME/.profile, does it matter whether $HOME/.bash_profile exists or not ?
|
6. When an application depends on a setting in `$HOME/.profile`, does it matter whether `$HOME/.bash_profile` exists or not?
|
||||||
|
|
||||||
## 31.10. practice: groups
|
## 31.10. practice: groups
|
||||||
|
|
||||||
1. Create the groups tennis, football and sports.
|
1. Create the groups tennis, football and sports.
|
||||||
2. In one command, make venus a member of tennis and sports.
|
2. In one command, make venus a member of tennis and sports.
|
||||||
3. Rename the football group to foot.
|
3. Rename the football group to foot.
|
||||||
4. Use vi to add serena to the tennis group.
|
4. Use `vi` to add serena to the tennis group.
|
||||||
5. Use the id command to verify that serena is a member of tennis.
|
5. Use the `id` command to verify that serena is a member of tennis.
|
||||||
6. Make someone responsible for managing group membership of foot and sports. Test that it works.
|
6. Make someone responsible for managing group membership of foot and sports. Test that it works.
|
||||||
|
|
||||||
## 32.4. practice: standard file permissions
|
## 32.4. practice: standard file permissions
|
||||||
|
|
||||||
1. As normal user, create a directory ~/permissions. Create a file owned by yourself in there.
|
1. As normal user, create a directory `~/permissions`. Create a file owned by yourself in there.
|
||||||
2. Copy a file owned by root from /etc/ to your permissions dir, who owns this file now ?
|
2. Copy a file owned by root from `/etc/` to your permissions dir, who owns this file now ?
|
||||||
3. As root, create a file in the users ~/permissions directory.
|
3. As root, create a file in the users `~/permissions` directory.
|
||||||
4. As normal user, look at who owns this file created by root.
|
4. As normal user, look at who owns this file created by root.
|
||||||
5. Change the ownership of all files in ~/permissions to yourself.
|
5. Change the ownership of all files in `~/permissions` to yourself.
|
||||||
6. Make sure you have all rights to these files, and others can only read.
|
6. Make sure you have all rights to these files, and others can only read.
|
||||||
7. With chmod, is 770 the same as rwxrwx--- ?
|
7. With `chmod`, is 770 the same as rwxrwx--- ?
|
||||||
8. With chmod, is 664 the same as r-xr-xr-- ?
|
8. With `chmod`, is 664 the same as r-xr-xr-- ?
|
||||||
9. With chmod, is 400 the same as r-------- ?
|
9. With `chmod`, is 400 the same as r-------- ?
|
||||||
10. With chmod, is 734 the same as rwxr-xr-- ?
|
10. With `chmod`, is 734 the same as rwxr-xr-- ?
|
||||||
11a. Display the umask in octal and in symbolic form.
|
11. Display the `umask` in octal and in symbolic form.
|
||||||
11b. Set the umask to 077, but use the symbolic format to set it. Verify that this works.
|
11. Set the `umask` to 077, but use the symbolic format to set it. Verify that this works.
|
||||||
12. Create a file as root, give only read to others. Can a normal user read this file ? Test writing to this file with vi.
|
12. Create a file as root, give only read to others. Can a normal user read this file ? Test writing to this file with vi.
|
||||||
13a. Create a file as normal user, give only read to others. Can another normal user read this file ? Test writing to this file with vi.
|
13. Create a file as normal user, give only read to others. Can another normal user read this file ? Test writing to this file with `vi`.
|
||||||
13b. Can root read this file ? Can root write to this file with vi ?
|
13. Can root read this file ? Can root write to this file with `vi`?
|
||||||
14. Create a directory that belongs to a group, where every member of that group can read and write to files, and create files. Make sure that people can only delete their own files.
|
14. Create a directory that belongs to a group, where every member of that group can read and write to files, and create files. Make sure that people can only delete their own files.
|
||||||
|
|
||||||
## 33.5. practice: sticky, setuid and setgid bits
|
## 33.5. practice: sticky, setuid and setgid bits
|
||||||
|
|
||||||
1a. Set up a directory, owned by the group sports.
|
1. Set up a directory, owned by the group sports.
|
||||||
1b. Members of the sports group should be able to create files in this directory.
|
1. Members of the sports group should be able to create files in this directory.
|
||||||
1c. All files created in this directory should be group-owned by the sports group.
|
1. All files created in this directory should be group-owned by the sports group.
|
||||||
1d. Users should be able to delete only their own user-owned files.
|
1. Users should be able to delete only their own user-owned files.
|
||||||
1e. Test that this works!
|
1. Test that this works!
|
||||||
2. Verify the permissions on /usr/bin/passwd. Remove the setuid, then try changing your password as a normal user. Reset the permissions back and try again.
|
2. Verify the permissions on `/usr/bin/passwd`. Remove the `setuid`, then try changing your password as a normal user. Reset the permissions back and try again.
|
||||||
3. If time permits (or if you are waiting for other students to finish this practice), read about file attributes in the man page of chattr and lsattr. Try setting the i attribute on a file and test that it works.
|
3. If time permits (or if you are waiting for other students to finish this practice), read about file attributes in the man page of `chattr` and `lsattr`. Try setting the i attribute on a file and test that it works.
|
||||||
|
|
||||||
## 35.6. practice: links
|
## 35.6. practice: links
|
||||||
|
|
||||||
1. Create two files named winter.txt and summer.txt, put some text in them.
|
1. Create two files named `winter.txt` and `summer.txt`, put some text in them.
|
||||||
2. Create a hard link to winter.txt named hlwinter.txt.
|
2. Create a hard link to `winter.txt` named `hlwinter.txt`.
|
||||||
3. Display the inode numbers of these three files, the hard links should have the same inode.
|
3. Display the inode numbers of these three files, the hard links should have the same inode.
|
||||||
4. Use the find command to list the two hardlinked files
|
4. Use the `find` command to list the two hardlinked files
|
||||||
5. Everything about a file is in the inode, except two things : name them!
|
5. Everything about a file is in the inode, except two things : name them!
|
||||||
6. Create a symbolic link to summer.txt called slsummer.txt.
|
6. Create a symbolic link to `summer.txt` called `slsummer.txt`.
|
||||||
7. Find all files with inode number 2. What does this information tell you ?
|
7. Find all files with inode number 2. What does this information tell you ?
|
||||||
8. Look at the directories /etc/init.d/ /etc/rc2.d/ /etc/rc3.d/ ... do you see the links ?
|
8. Look at the directories `/etc/init.d/` `/etc/rc2.d/` `/etc/rc3.d/` ... do you see the links ?
|
||||||
9. Look in /lib with ls -l...
|
9. Look in `/lib` with `ls -l`...
|
||||||
10. Use find to look in your home directory for regular files that do not(!) have one hard link.
|
10. Use `find` to look in your home directory for regular files that do not(!) have one hard link.
|
||||||
|
|
Loading…
Reference in New Issue