Homework 8

Users, Groups, Permissions

This assignment involves the Unix multi-user system and permissions.

Download the homework files on attu

After logging into attu, download the homework files.

git archive --remote=git@gitlab.cs.washington.edu:cse391/25wi/hw8.git --prefix=hw8/ -o hw8.tar.gz HEAD

This will download the code in the file hw8.tar.gz. Your first problem will be to figure out how to unzip this file using the tar command to extract files in this tar (tape archive) file format. Unlike zip archives that you’ve seen before, tar does not provide compression on its own. Most .tar files are then compressed with a separate compression algorithm like gzip, which yields a tar.gz file. tar.gz files tend to be quite common in Unix environments, so it’s helpful to learn how to extract them.

Task 1: Bash shell commands

For this task, we will compose shell commands with input/output redirection operators such as >, >>, <, |, &&, and ;. For each item below, determine a single bash shell statement that will perform the operation(s) requested.

Write your answers on the indicated lines in the task1.sh file in the hw8 folder that results from extracting the hw8.tar.gz file.

  1. What is the command that extracts the file hw8.tar.gz into the current directory in “verbose” mode such that all extracted file paths are displayed? This command does not require any pipes or redirection.
  2. What is the command that sets the file README.md so that its owner and others can execute the file? All other permissions should remain unchanged.
  3. What is the command that sets all .java files in the current directory and all its subdirectories (and sub-sub-directories, etc. recursively) to have read permission for all users?
    1. What is the command that sets all files with extension .html in the current directory and all its subdirectories (recursively) to be readable, writeable, and executable by their owner and only readable (not writeable or executable) by groups and others? Do this using the standard letter code arguments for granting and removing permissions. Some filenames contain spaces, which will cause problems. Read the man pages for ways to handle file names with spaces.
    2. What is the command that achieves the same result but using the octal number code arguments to grant or revoke permissions?
  4. What is the command that sets all files in the current directory and all its subdirectories (recursively) to be owned by the group wheel? The particular group wheel might not exist on attu, so you may want to test with ugrad_cs or ugrad_ce instead.
  5. What is the umask command to set the default permissions for new files to have read (but not write or execute) permission for you (the owner), while having no permissions for anyone else? The umask command is used to specify what permissions are given by default to newly created files. Somewhat counterintuitively, the arguments specify what permissions will be taken away.
  6. What is the simplest possible sudo command that invokes cat to print the contents of the file /etc/ssh/sshd_config? attu is configured with a fake sudo binary that will print a fake sshd_config file if the correct, simplest possible arguments are given.

Task 2: .bashrc

Write your answers in your ~/.bashrc file and submit your modified .bashrc file.

  1. Add an alias attu connects you to attu.cs.washington.edu via ssh. (This alias isn’t very useful if you’re testing on attu itself, but set it up anyway.)
  2. Add an alias mv so that it prompts for user input before overwriting a file during a move operation. In the man pages, this is called interactive mode.
  3. Add an alias cp so that it prompts for user input before overwriting a file during a copy operation.

Submitting a hidden file like .bashrc can be somewhat complicated because many computer operating systems tend to hide hidden files by default. To unhide them so you can upload them to Gradescope:

macOS
In Finder, Command Shift . (period key) toggles display of hidden files.
Windows
In File Explorer, under the View | Show menu, select Hidden items.
ChromeOS
In Files, under the three-dot menu, choose Show hidden files.

Task 3: .bash_profile

In general, if you want to personalize your environment with programs that print output to the terminal, put them in your .bash_profile rather than in your .bashrc. Write your answer in your ~/.bash_profile file and submit your modified .bash_profile file..

  1. Display a personalized message when logging on to the system, like “Welcome! Have a great day!” You can do this by just listing the command you would execute at the bottom of your .bash_profile. Feel free to get creative with this! Anything will be fine here as long as it prints some output to the screen that would not have happened otherwise.