Understanding Passwords

Assignment: Passwords, Accounts, and SSH

  1. You have received a new batch of distinguished visitors; their basic information is located in newusers.txt. This file contains a colon-separated entry for each user: the username, the uid, the GECOS information, and the user's preferred shell.
  2. My advice is to write a Bash script to add these visitors to both your host and guest machine as local users (you might to verify that no name clashes occur, though, before you proceed!) If you want to do this exercise by hand (and a few students over the years have done so), please feel free to do so.
  3. Most (but not all) of these visitors have provided a public key (or, more informally, "pubkey"), and these pubkeys are at stored at "https://www.cs.fsu.edu/~langley/NEWKEYS/".
  4. The filename pattern for these pubkeys is "USERNAME.pub". For instance, you can use "wget http://www.cs.fsu.edu/~langley/NEWKEYS/jones.pub" to retrieve the pubkey for user "jones".
  5. I suggest that your Bash script should expect two arguments, the name of the users file file ("newusers.txt", in this case) and the URL where public keys for these users can be found (in this instance, "https://www.cs.fsu.edu/~langley/NEWKEYS/").
  6. The script could, for each new user, create a home directory with the usual files from /etc/skel, but put the home directories in /home/visitors/USERNAME/, not just /home/USERNAME.
  7. Please use the user id from the file to create the home directories. Each user should also have an individual group, where the group id matches the user id. Don't assign passwords to these accounts; instead, set it up so that the users can login using the public key provided at the URL. This means a copy of the public key needs to be placed in a file name "/home/visitors/USER/.ssh/authorized_keys" (which can contain many such keys, which is best practice for different originating accounts --- you probably should not copy the same private key over multiple machines.)
  8. In general, setting up public key access via ssh is slightly tricky, and you must pay close attention to file and directory permissions. Also, Arch is among the distros that make this more finicky than not. In particular, Arch now requires you to manually generate "host keys" as root, using "ssh-keygen -A" during your sshd configuration.
  9. Please add a test user to the newusers.txt with a public key for whom you also have the corresponding private key and verify that you can ssh into this test user's account, and that all permissions and directories are set up correctly for that user from within that okay.
  10. Also create a /scratch/USERNAME/ directory for each user, and make sure that it is owned by the correct user and has the correct group number.

As a suggestion, your internal loop could look something like

while IFS=: read name uid gecos homedir
do
   [ .... ]
done < $userfile
although of course there are many ways to do this, such as using "mapfile" to create an array to iterate over.