p3_DFS_auth_rdist
p3_DFS_auth_rdist
Project 3:
Administering and Using a Distributed File System
Now that we have set up networking and Network Information Service (NIS) on your Virtual
Machine (VM), we can take advantage of this in order to implement some more advanced
features for your VMs file system. We will then build on this in order to enable new
practices, such as the use of SSH key pairs for user authentication and remote distribution
of system-level data updates.
(This much, I or previous admins have already done. You should just read it, in order to
understand the server-side configuration done on it20.):
1. Download and install the required NFS packages:
sudo apt-get update
sudo apt-get install nfs-common
sudo apt-get install nfs-kernel-server
We want user sysadmin, on it20 and on all the clients, to be local and so not part of
NFS. Having sysadmin allows us access to any host, whether or not NFS is running
properly. So we are explicit as to where its home is (its new path location).
1
https://help.ubuntu.com/community/SettingUpNFSHowTo
https://help.ubuntu.com/16.04/serverguide/network-file-system.html
6. Edit /etc/auto.master to tell autofs about the map for /home. The directory
/home must exist and must be empty. It must not have any files in it. Remember we
moved the /home directory earlier in the project.
# $Id: auto.master,v 1.4 2005/01/04 14:36:54 raven Exp $
#
# Sample auto.master file
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
...
#/net /etc/auto.net
/home /etc/auto.home
The task on the clients is similar. In fact, when it comes to NFS we are all both servers and
clients. We are servers in that we serve up (or export) our local home directories to the
network. We are clients in that we (auto) mount the local directories that are served up
(exported) by other hosts on the network.
Of course, in these examples, both itvm28-8a and user bja are just examples. You will want
to use your itvm2x-yz (replacing x, y and z with the actual values) and your usernames.
2. Move the homes to another location, from the root / directory, by changing the name
of the original /home directory, incorporating your VM's name
4. On every host (both the server and clients) we want user sysadmin to be a truly local
user and not part of NFS. Edit /etc/passwd to say where user sysadmin’s home is:
sudo nano /etc/passwd
...
libuuid:x:100:101::/var/lib/libuuid:/bin/sh
landscape:x:102:108::/var/lib/landscape:/bin/false
sysadmin:x:1000:1000:sysadmin,,,:/home.itvm28-8a/sysadmin:/bin/bash
sshd:x:103:65534::/var/run/sshd:/usr/sbin/nologin
statd:x:104:65534::/var/lib/nfs:/bin/false
...
5. Depending on the editor you are using you may get an error message. Ignore it. At this
point sysadmin does not have a home directory. Why? Think about it and be
prepared to address it in the discussion questions. You need to logout and log in
again. Then sysadmin will again have a home directory.
6. Edit /etc/auto.master to tell autofs about the map for /home. The directory
/home must exist and must be empty. It must not have any files in it. Remember we
moved the /home directory earlier in the project. (Do not worry about your file's current
contents. Just focus on adding the specified line at the end.)
sudo nano /etc/auto.master
#
# Sample auto.master file
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# For details of the format look at autofs(5).
#
#/misc /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
# "nosuid" and "nodev" options unless the "suid" and "dev"
# options are explicitly given.
#
#/net -hosts
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
/home /etc/auto.home
7. Then, back to the server it20, an administrative user – in other words, a sudo-er – will
need to edit /etc/auto.home to mount bja’s home:
# Ampersand in the RHS matches the key itself. NOTE: There is no actual
abird it20:/home.it20/&
it341 it20:/home.it20/& user named "bja" – that
ajb it20:/home.it20/& username is just an
bja itvm28-8a:/home.itvm28-8a/& example!
...
By the time your reach this step, the file /etc/auto.home on it20 will have been
edited so that it contains a line with your username and where your home can be found
on the network. You will need to copy the file /etc/auto.home from it20 to the
same absolute filepath on your virtual machine. This is best accomplished using scp
sudo scp it341@it20:/etc/auto.home /etc/auto.home
8. Eventually, all clients will have exported all of their home directories, as well as copied
over the /etc/auto.home file from it20. We will all (server and clients) want to
automount all homes from all servers; indeed, /etc/auto.home will look the same on
all hosts.
9. At this point, run two commands:
sudo service nfs-kernel-server restart
sudo service autofs restart
10. Now, we should be able to log on to any hosts (because NIS makes us known to our
network), and we should see our home directories on each of these hosts (because NFS
makes them available). This, of course, is true only to the extent that all hosts have
successfully implemented networking, NIS, and now NFS. Indeed, NFS makes it look like
there is just one common /home visible to all hosts. In reality, our own home directories
reside on our own hosts (as /home.itvm2x-yz) but we export them to the network
and each host automounts these under /home, as needed.
11. You may notice that if, on your VM, you cd to /home, you may not see all home
directories; it may look as follows:
abird@it20:~$ cd /home
abird@it20:/home$ ls
abird
But, when you explicitly ask for another user's home...
abird@it20:/home$ ls bja
abird@it20:/home$ ls
bja abird
This is because the automounter only mounts the directories on demand ... once you
actually refer to (or ask for) the directory explicitly, as in this example:
abird@it20:/home$ ls bja
We can also copy files from elsewhere to our own host. For example, to copy itvm28-8a’s
/etc/hosts file to it20’s /tmp, we could say:
Key‐Based Authentication
One thing you may have noticed is that it would be a lot easier if we could push stuff (common
files, etc.) from it20 out to the client itvm28-8a. And we would like to do so without having to
supply a password every time.
So, we will set up key‐based authentication. Following the text, we will use a non‐empty
passphrase. Of course, this puts us back in the position of having to supply a pass phrase in
place of a password. But we can then use ssh‐agent for managing the passphrase exchange
whenever we are challenged. As you have read in the text, ssh‐agent caches the passphrase
in memory while the current shell is active; when the shell dies, the pass phrase goes with it.
OK, so now our ssh client is it20 and our ssh servers (from whom we want to push out files)
are the VMs. In our example, we will set up key‐based authentication with itvm28-8a; we use
it here only as an example.
On the virtual server:
1. You should first read the section on key‐based authentication in the textbook.
2. Log in to your VM as yourself. For the user Al Bird, and in the examples below, it’s abird. When
you do this, use your own username that we created for you on it20 in the previous project.
3. The first thing we have to do is generate a public/private key pair with the ssh‐keygen utility.
We will use the passphrase qazxsw (which is easier to type than you might think).
abird@itvm28-8a:~$ ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/home/abird/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again: Type qazxsw Leave blank
and press
Your identification has been saved in /home/abird/.ssh/id_rsa. Your Enter
public
key has been saved in /home/abird/.ssh/id_rsa.pub.
The key fingerprint is:
2e:98:6f:72:9f:70:9c:37:11:c1:fc:ed:91:9b:b8:09 abird@itvm28-8a
The key's randomart image is:
+--[ RSA 2048]----+
| o. |
| o. |
| .. . . |
| .. + |
| S . o + |
| o o .E.. + |
| o o = o. o |
| ..o+ o .o |
| +..o |
+-----------------+
abird@itvm28-8a:~$
Welcome to Ubuntu!
* Documentation: https://help.ubuntu.com/
Instead of asking for abird’s password, it asks for the passphrase for abird’s
authentication key. Make sure you understand why this works. Be prepared to write about
it in your discussion questions....
6. We can make even more progress. We would like to be able to ssh into other machines
without having to supply the passphrase each time. The ssh‐agent utility allows us to do
this within the scope of a single, ongoing login session.
7. Again, let us log out and return to itvm28-8a. Here we invoke ssh‐agent with the name
of the shell we want to use as its argument:
abird@it20:~$ exit
Connection to it20 closed.
abird@itvm28-8a:~$ ssh-agent /bin/bash
abird@itvm28-8a:~$
abird@itvm28-8a:~$ ssh-add
Enter passphrase for /home/abird/.ssh/id_rsa:
Identity added: /home/abird/.ssh/id_rsa (/home/abird/.ssh/id_rsa)
abird@itvm28-8a:~$
ssh‐add adds RSA (or DSA) identities to the authentication agent, ssh‐agent. When run
without arguments, it adds the files
Welcome to Ubuntu!
* Documentation: https://help.ubuntu.com/
2
In practice, one chooses a single host, usually a server from which to distribute files but we are just playing here – so play
away.
3
When you do this, it is a good idea to install any updates available.
(If you are not familiar with scripting in a Linux-based environment, consider brushing up on this
topic. Google phrases like linux shell script tutorial )
By default, rdist uses the (non-secure) rsh for transport. We want to use the more secure ssh.
So, we create our own script myrdist – which invokes rdist with the proper parameters:
We start by creating the myrdist file (which each partner should do):
johndoe@itvm28-8a:~$ nano myrdist
• Add the following to the file:
•
#!/bin/sh
# A preconfigured rdist that uses ssh
SSH="`which ssh`"
RDISTD="`which rdistd`"
This specifies that to satisfy the target hosts, we copy file /etc/hosts to itvm28-1b, and
install it as /etc/hosts there. (Again, you should not actually do this!!!)
Be extremely careful; a wrong Distfile can cause havoc! See below.
Running rdist
To run rdist, we simply type rdist, or to use our configured version, myrdist. But
before doing so, we can modify our Distfile by adding a verify option to the install:
What are some of the most important options available for rdist? Why is that? Be prepared to
write about this in your discussion questions...
Play in a sandbox
Before using rdist to distribute files to an important directory such as /etc, set up a sandbox
and practice there. For example, use /tmp as the destination directory.
NOTE: The following section is not intended to be carried out by you. It is just here to serve as an
example.
rdist
is fine as you specify a file name as the destination; rdist will write a new hosts file in /etc.
However…
is disastrous. It would overwrite the /etc directory with the file hosts, removing /etc contents
altogether. (It has happened to previous instructors!)
…then the behavior is as you would expect: the two files hosts and nsswitch.conf are copied
into directory /etc on itvm28-1b. What precautions can you take in order to keep yourself
from making such? These will be addressed in the discussion questions...
Also, you can ask that one directory overwrite another directory. The following would overwrite
/etc on itvm28-1b with the /etc on the machine running rdist
hosts: /etc -> ( itvm28-1b )
install /etc ;
Experiment with various Distfiles. And, be careful! Never use a target that doesn’t involve
/tmp
Discussion Questions:
1. After you edit /etc/passwd on your VM, you might get an error message to the
effect that sysadmin does not have a home directory.
a. Whether or not you experience this, why could something like that happen?
b. After you log sysadmin out -- and then back in -- sysadmin should have a
home directory once more. Why would this be the case?
2. How is mounting other users' homes in this project dependent upon the correct
configuration of networking and NIS in Project 2?
3. When you make changes in your home directory (such as adding, deleting, or
editing files) while logged into it20 or someone else's VM, why do those changes
persist in your home directory, as it exists on your own VM?
4. What differentiates ssh, scp, and sftp from their non-secure counterparts (rsh,
rcp, and ftp)? In other words, what makes them "secure"?
5. In Part II, Step #5, we saw that the example user abird was prompted for a
passphrase instead of a password. Why does this occur?
6. Using key pairs...
a. When a user (on his/her local machine) authenticates to a remote host using a
key pair, what are the respective roles of the public and private keys?
b. Which keys (public vs. private) must be on which hosts (local vs. remote) for
authentication to take place, and why is this the case?
7. How does NFS-based mounting enable us to create one pair of key files in our home
directories – in our .ssh folders – and then be able to log into (and from) any Linux
machine within the IT Lab LAN?
8. Identify some of the most important options to the rdist command and explain
their significance.
9. If you were going to use rdist to push an update to other machines' /etc
directories, what are some precautions you can take to ensure that you do not
accidentally damage/destroy any essential files on those machines?
10. How can ssh-agent make it easier to execute the rdist command?