Operating Systems 2018F: Tutorial 6: Difference between revisions
No edit summary |
Housedhorse (talk | contribs) |
||
(One intermediate revision by one other user not shown) | |||
Line 4: | Line 4: | ||
# Run <tt>ls -lai</tt> (by itself or for a specific directory). What are the numbers appearing in the left column? | # Run <tt>ls -lai</tt> (by itself or for a specific directory). What are the numbers appearing in the left column? | ||
# dd if=/dev/zero of=foo bs=8192 count=32K What is the logical size of the file? How much space does it consume on disk? (Hint: Look at the size option to ls.) | # Run dd if=/dev/zero of=foo bs=8192 count=32K What is the logical size of the file? How much space does it consume on disk? (Hint: Look at the size option to ls.) | ||
# Run <tt>mkfs.ext4 foo</tt>. (If asked, say "yes" to operating on a regular file.) Does foo consume any more space? | # Run <tt>mkfs.ext4 foo</tt>. (If asked, say "yes" to operating on a regular file.) Does foo consume any more space? | ||
# Run <tt>dumpe2fs foo</tt>. What does the output of this command mean? | # Run <tt>dumpe2fs foo</tt>. What does the output of this command mean? | ||
Line 97: | Line 97: | ||
# Can you access sshfs mounted files as root? (You can become root by typing "sudo su -".) What happens? | # Can you access sshfs mounted files as root? (You can become root by typing "sudo su -".) What happens? | ||
# Look at inode numbers in local and remote filesystems (as reported by ls -i). How do they compare? | # Look at inode numbers in local and remote filesystems (as reported by ls -i). How do they compare? | ||
# dd a large file to local drive. Do same thing over sshfs. Which is faster? (What is a large file in this context?) | # dd a large file to a local drive. Do same thing over sshfs. Which is faster? (What is a large file in this context?) | ||
# Can you sshfs to the SCS systems (e.g., access.scs.carleton.ca)? | # Can you sshfs to the SCS systems (e.g., access.scs.carleton.ca)? | ||
# Setup password-less login to the SCS system (and then undo it). | # Setup password-less login to the SCS system (and then undo it). | ||
# How can you use the mount command to unmount a sshfs-mounted filesystem (rather than fusermount)? | # How can you use the mount command to unmount a sshfs-mounted filesystem (rather than fusermount)? | ||
Latest revision as of 19:42, 28 October 2018
In this tutorial you will be playing with filesystems (regular filesystems and sshfs). Please use a VM and make backups, as some of these commands could erase all data on your system.
Creating, Mounting, and Unmounting Filesystem
- Run ls -lai (by itself or for a specific directory). What are the numbers appearing in the left column?
- Run dd if=/dev/zero of=foo bs=8192 count=32K What is the logical size of the file? How much space does it consume on disk? (Hint: Look at the size option to ls.)
- Run mkfs.ext4 foo. (If asked, say "yes" to operating on a regular file.) Does foo consume any more space?
- Run dumpe2fs foo. What does the output of this command mean?
- What command do you run to check the filesystem in foo for errors?
- Run sudo mount foo /mnt. How does this command change what files are accessible?
- Run df. What device is mounted on /mnt? What is this device?
- Run rsync -a -v /etc /mnt. What does this command do? Explain the arguments as well.
- Run sudo umount /mnt. What files can you still access, and what have gone away?
- Run dd if=/dev/zero of=foo conv=notrunc count=10 bs=512. How does the "conv=notrunc" change dd's behavior (versus the command in question 1)?
- Run sudo mount foo /mnt. What error do you get?
- What command can you run to make foo mountable again? What characteristic of the file system enables this command to work?
- Run the command truncate -s 1G bar. What is the logical size of bar, and how much space does it consume on disk? How does this compare with foo?
- How does the logical size of bar change when you create an ext4 filesystem in it? What about the space consumed on disk?
SSH & SSHFS
Here you will be learning about ssh (openssh) and sshfs, a network filesystem built on FUSE.
Setup
Install the openssh-server and sshfs packages:
sudo apt-get install openssh-server sshfs
Create a second user in the virtual machine named "other" (or any other name you wish to use):
sudo adduser other
(Answer the subsequent prompts however you wish, just remember the password.)
At this point you should be able to log in to the "other" account using ssh:
ssh other@localhost
You'll have to enter your password.
If you don't get a password prompt, password authentication has probably been disabled. (Password authentication has been disabled on the openstack VMs.) To enable it, do the following
sudo nano /etc/ssh/sshd_config (or vi, or emacs)
In the editor change the line "PasswordAuthentication no" to "PasswordAuthentication yes". Then, to restart sshd:
sudo service sshd restart
Be sure to change it back after you've set up public key authentication!
Remote filesystems using sshfs
To mount the other user's files in a directory called "otherfiles", do the following (as user student, ubuntu, or your personal account):
mkdir otherfiles sshfs other@localhost: otherfiles
To unmount the filesystem:
fusermount -u otherfiles
Public key authentication and ssh
Create a public key file for your account (as user student, ubuntu, or your personal account):
ssh-keygen
(Accept the default filename and choose at least a simple passphrase.)
You just created a certificate! (A certificate is just a public key with metadata.)
Copy the key to the other account:
cat ~/.ssh/id_rsa.pub >> authorized_keys scp authorized_keys other@localhost:. rm authorized_keys ssh other@localhost
(as user other) mkdir ~/.ssh (if it doesn't exist already) chmod 700 ~/.ssh (make it private) mv ~/authorized_keys ~/.ssh chmod 600 ~/.ssh/authorized_keys
Now you can log in to user other by typing in the passphrase you used to lock the key you generated.
To avoid entering this passphrase every time, you can give it to the authentication agent (generally, ssh-agent) that was started when you logged in:
ssh-add
Note I expect the above to be a bit confusing. Do look around for resources on public key cryptography; however, you may find that playing around with ssh authentication may help you understand things better. In particular, try using "-v" (verbose) with ssh.
Tasks
- Look at the hard link counts of files locally and compare those to the link counts over sshfs. How do they compare?
- Can you access sshfs mounted files as root? (You can become root by typing "sudo su -".) What happens?
- Look at inode numbers in local and remote filesystems (as reported by ls -i). How do they compare?
- dd a large file to a local drive. Do same thing over sshfs. Which is faster? (What is a large file in this context?)
- Can you sshfs to the SCS systems (e.g., access.scs.carleton.ca)?
- Setup password-less login to the SCS system (and then undo it).
- How can you use the mount command to unmount a sshfs-mounted filesystem (rather than fusermount)?