SSH and SSHFS Cheat Sheet

Access Remote System Locally as Root using SSHFS

Sometimes editing remote files owned by root with an editor like vi is ineffective.  Because sshfs provides access to remote files as a local file system mount, you can use any local IDE on those remote files.   If you also have sudo access on remote host, you can set the sftp_server option as below to mount the remote file system with root access. 

Important: Use the follow_symlinks option to avoid remote links mapping to local files... for example if the remote /etc/nginx/sites-enabled/default is a symlink pointing to /etc/nginx/sites-available/default, it will map to your local nginx!

pkcinna@mini:~$ mkdir -p remote/root-www
pkcinna@mini:~/remote$ sshfs  -o follow_symlinks -o IdentityFile=~/.ssh/ec2 -o sftp_server="/usr/bin/sudo /usr/lib/openssh/sftp-server" ubuntu@www.xmonit.com:/ /home/pkcinna/remote/root-www

# remove mount when done
pkcinna@mini:~/remote$ sudo umount root-www

** NOTE: This only works if the user has sudo NOPASSWD access to sftp-server.  You may need to add a line like this to the end of /etc/sudoers:

SOME_SSH_USER_HERE    ALL=(root) NOPASSWD: /usr/lib/openssh/sftp-server

 

Tags