Sharing Files Between Users on OpenBSD

My brother and I have been working on a project together recently and it became apparent that we could benefit from having a place to share some audio and video files with eachother. I have an OpenBSD server co-located at a local ISP and I thought “why not use that?”

Users and groups

I started out by making user accounts and home directories for both of us with useradd:

useradd -m me
useradd -m him

I also set a password for each account so security wouldn't complain about them being partly-closed, though I planned to use ssh keys for logging in.

Then I created a group that we could each be a member of and which could own the shared directory. For this I used groupadd. I specified the group ID to be up out of the way of the groups that are automatically created for each user, but this was not strictly necessary.

groupadd -g 10000 ourgroup

To make each of us members of the group, I ran usermod:

usermod -G ourgroup me
usermod -G ourgroup him

Directory and partition

I thought I would like to put our shared folder at /g/ourgroup. hier does not indicate a place set aside for files shared among members of a group. This is fine since it only claims to the filesystem hierarchy that ships with the system. I think using /g for files shared among members of a group is (or at least was) a common practice, perhaps paralleling the once-upon-a-time placement of user home directories in /u. In any event, I started by creating the directory with mkdir -p /g/ourgroup.

When I originally set up the server, I let the OpenBSD installation program automatically lay out the partitions on the main disk array. It was able to provide generous partitions for var and home while still leaving almost half of the array unallocated, so I had some space available for this project. I used disklabel to add a new partition of 200GB:

host# disklabel -E sd0
Label editor (enter '?' for help at any prompt)
sd0> a l
offset: [1118131072] 
size: [1223856758] 400000000
FS type: [4.2BSD] 
sd0*> p
OpenBSD area: 64-2341987830; size: 2341987766; free: 823856782
#                size           offset  fstype [fsize bsize   cpg]
  a:          2097152               64  4.2BSD   2048 16384 12958 # /
  b:        134683592          2097216    swap                    # none
  c:       2341994496                0  unused                    
  d:          8388576        136780832  4.2BSD   2048 16384 12958 # /tmp
  e:        276707200        145169408  4.2BSD   4096 32768 26062 # /var
  f:          6291456        421876608  4.2BSD   2048 16384 12958 # /usr
  g:          2097152        428168064  4.2BSD   2048 16384 12958 # /usr/X11R6
  h:         41943040        430265216  4.2BSD   2048 16384 12958 # /usr/local
  i:          4194304        472208256  4.2BSD   2048 16384 12958 # /usr/src
  j:         12582912        476402560  4.2BSD   2048 16384 12958 # /usr/obj
  k:        629145600        488985472  4.2BSD   4096 32768 26062 # /home
  l:        400000000       1118131072  4.2BSD   4096 32768     1 
sd0*> w
sd0> q
No label changes.

With the partition created, I ran newfs sd0l to construct a new file system on it. Then I was ready to add it to /etc/fstab with a line like [DUID].l /g/ourgroup ffs rw,nodev,nosuid 1 2. Finally, I was able to mount the new file system with mount /g/ourgroup.

When a file system is mounted to a mount point, the path refers to the mounted vnode rather than the vnode of the mount point (see, for example, vfs_lookup() in src/sys/kern/vfs_lookup.c), so getting or setting ownership or permissions on this path updates the mounted vnode (root inode of the new file system in this case). So now that the new file system was mounted, it was time to change its group and make it writable by group members:

chgrp ourgroup /g/ourgroup
chmod g+w /g/ourgroup

Moving files

My brother and I both use Transmit 5 to move files around. I performed the same setup steps on each of our workstations.

I started out by going to the Keys tab of Preferences and creating a new key. I took the option to copy the new public key to the clipboard and appended it to ~/.ssh/authorized_keys on the server (using the root account to su to the respective user account first).

Next, I added an SFTP server in Transmit. I set the server title (or nickname), address, and user name. Instead of a password, I selected the new key I had just created. For convenience, I set the remote path to /g/ourgroup.

Back in Preferences, I found I could set “Windows open with” to have Transmit connect to and bring up the server in the right pane automatically when the program starts. I was also able to drag a couple of common locations on the server (like my home directory and the shared directory) into the locations bar on the server side of the window for easy access. We move some larger files around, so I found it handy to turn on the progress bar at the bottom of the window. That option was in the View menu.

We're now happily sharing our files back and forth, using old-school tech with a modern twist. I hope that you found this helpful. If this is the kind of thing you're into, you may enjoy my other work. If you have any questions or comments, please drop me a line at the address below.

Aaron D. Parks
Parks Digital LLC
4784 Pine Hill Drive, Potterville, Michigan