I'd like to be able access files from a server using sshfs. For this, sshfs needs a folder as a mount point.
When I insert a usb drive and open it via my file manager (thunar), a folder in /run/media/$USER is automatically created without me providing root permissions:
$ ll /run/media/slammer/
total 0
drwxr-x---+ 2 root root 40 Aug 8 12:37 ./
drwxr-xr-x 3 root root 60 Aug 8 12:17 ../
$ # inserting usb drive now
$ ll /run/media/slammer/
total 0
drwxr-x---+ 2 root root 40 Aug 8 12:37 ./
drwxr-xr-x 3 root root 60 Aug 8 12:17 ../
$ # clicking 'Mount and Open ...' in file manager (thunar)
$ ll /run/media/slammer/
total 4
drwxr-x---+ 3 root root 60 Aug 8 12:38 ./
drwxr-xr-x 3 root root 60 Aug 8 12:17 ../
drwxrwxrwx 1 slammer slammer 4096 Jun 28 14:22 'TOSHIBA EXT'/
$ # a new folder 'TOSHIBA EXT' appeared
How can I create a folder like this without root permissions, such that I can then use it as mount point for sshfs?
Update 1
Since I have not found a way to create the folder as I wanted to, I instead created a wrapper script that creates the mountpoint in ~/.sshfs/<myserver> (for now; I dislike that I have another folder in my home directory, but I havn't come up with a better alternative).
#!/bin/sh
# Automatically creates mountpoint for sshfs before runnning the sshfs command itself.
MOUNT_DIR_PARENT="$HOME/.sshfs"
SSHFS="sshfs"
host=`echo $@ | sed -E 's/^([^:]+):.*$/\1/;t;q1'`
status=$?
if [ $status -ne 0 ]; then
echo "Invalid host" >&2
exit $status
fi
set -e
mountpoint="$MOUNT_DIR_PARENT/$host"
mkdir -m 700 -p "$mountpoint"
echo $SSHFS $@ \"$mountpoint\"
$SSHFS $@ "$mountpoint"
https://github.com/SimonLammer/dotfiles/blob/master/data/scripts/sshfs_auto.sh
On your system there a deamon running udisksd started on demand by D-Bus that manages the mountpoints. This deamon runs as root.
Overall, your user shouldn't be mounting to /run/media. Just mount inside your home dir. You are an user, your home dir is your domain. Rest of the system is owned by the system.
You can write your own deamon to communicate via D-Bus that will mount it.
You can communicate with udisks2 to mount your stuff via sshfs.
You can change the permissions of /run/media/slammer/ folder so it is accessible by a normal user.