Jun 11

FUSE and sshfs are two amazingly useful pieces of tech that exist in the linux kernel. The idea of FUSE is to allow file system drivers to exist in user space instead of requiring kernel support. sshfs allows you to mount a remote file system using ssh and access it just like you would any other file system. I use it, for example, to mount my remote website provider to do backups and copy files around. Good stuff. So here are the three little commands that you’ll need to run in order to use sshfs in Ubuntu. This has been ripped from various sources on the internet, so props to the authors.
Install sshfs

sudo apt-get install sshfs

Add your users to the fuse user group where $USER is your userid

sudo adduser $USER fuse

Mount something where $USER is your remote userid and $REMOTEHOST is the remote system you want to mount.

sshfs $USER@$REMOTEHOST:/files /mnt/files

Unmount it when you’re done

fusermount -u /mnt/files

Really neat to play with and the remote nodes don’t have to be linux. They can be solaris, AIX, etc

Apr 1

ssh has a handy tool called scp that allows you to send files between machines over an encrypted connection. Some admins though don’t care much for this and remove the scp program. You can still move files around over ssh though using good old unix STDOUT and STDIN.

cat $FILE | ssh $USER@$HOST “cat >$FILE”

$FILE is the file that you want to send. What we’re doing here is using cat to dump that file (it can be a binary file) and then piping that into the input of ssh. ssh is intelligent enough to go through it’s authentication before it bothers with any of the data that is being dumped to STDIN and that last command tells ssh on the remote end to take everything that is being put into this side and push it out into a file called $FILE on that side. This allows for an easy way to copy over entire directories without having to waste space by making copies and tar files

tar cpf – $HOME | ssh $USER@$HOST “tar xvf -”

That one liner takes and creates a tar file of $HOME, but instead of creating a file, it dumps the tar to STDOUT, which is piped into STDIN of ssh and sent over the ssh tunnel. It’s then sent out of STDOUT in ssh into STDIN of tar which explodes the tar image back into files. We’ve just created a tar file, moved it to a new host and exploded it without using a single extra bit of space.

Mar 28

When you absolutely, positively have to kill every mother fu need to have X windows access to a remote system, I suggest using SSH. If you can ssh to a host, you can run any X application and have it display on your desktop. A situation where I use this all the time is when I need to run sun console admin on a remote host. You’ll need to make sure that X forwarding is enabled in the remote nodes sshd_config

X11Forwarding Yes

and then connect to that host with a -X flag

ssh -X $USER@$HOST

Done and done. You can run any x program now from firefox to xeyes.

Mar 27

Rsync has to be one of my favorite tools. It’s cross platform (a windows variant even exists) and it’s saved my bacon more times then I can count. rsync is designed, as the name somewhat implies, to synchronize file(s) across different hosts or directories. It handles permissions, ownerships, crazy file names and is a very complete tool. Two scenarios that I use rsync for a lot are syncing up my mp3 player and moving directories from one unix server to another. To sync two local directories (mp3 player example) I run the following

rsync -auv $SOURCE/*.mp3 $DEST

Pretty straight forward. rsync -a(keep permissions and ownership) -u(update files that already exist on the $DEST) -v(show me lots of output)

Taking that one step further, rsync can use ssh to move files between nodes. When using ssh, rsync is intelligent enough to move only the bits of the file that have changed. So if you have a 10 meg file that you want to sync but have only changed 1k of data on that file, rsync will move that 1k of data and then reassemble the file on the remote end to include those changes. Really really slick little program. You can move data between hosts like so

rsync -auv $SOURCE $USER@$HOST:$DEST

Again, pretty easy to understand. All we added was $USER@$HOST and a colon. Now files on $SOURCE will be copied over to $DEST using ssh as use $USER. I use this fairly frequently to upgrade my wordpress install when a new update comes out.