It can be a bit of a pain doing Python development over ssh with the Raspberry Pi. You’re limited to text-mode editors unless you start an X environment. The alternative is to edit files on your PC and sync them to the Pi for testing, but that’s fiddly end error-prone.
If you’re running Linux on your PC you can mount files from your PC’s filesystem on the Pi or vice versa. You can then edit programs on your PC with your favourite editor and run programs on the Pi without having to sync at all.
If you mount a directory on the Pi into your PC’s filesystem, the files remain on the Pi when you unmount the directory from your PC, so you can edit programs on the Pi with your PC and leave them running on the Pi when you finish working.
If you mount a directory on your PC into the Pi’s filesystem, you can continue working on the program on your PC even when you’ve unmounted it from the Pi – handy if you want to work on the move – and then remount it to run your program on the Pi.
My favourite tool for doing this is sshfs. It uses ssh and sftp as the transport and so there’s no need to edit system-global configuration files, as you do to export NFS directories, and you don’t need to be root to export or mount a filesystem.
You’ll need to install sshfs on your PC and your Raspebrry Pi. On each machine, install it with apt-get:
% sudo apt-get install sshfs
You need to add yourself to the fuse group to mount FUSE filesystems like sshfs. On each machine, run
% sudo adduser $USER fuse
Now log out and back in again and you’ll be able to mount remote directories into the filesystem on the Pi:
% mkdir quick2wire
% sshfs -o idmap=user -o gid=`id --group` firstname.lastname@example.org:quick2wire quick2wire
(Replace “192.168.1.4″ with the IP address or hostname of your PC and “nat” with your user id on your PC.)
Now you can edit the files on your PC, and run them on the Pi immediately.
Automating logon to the Pi
You’ll get asked to enter your password each time you want to connect. If you use an SSH key-pair, life is even simpler; ssh will use the keys to log you in without you having to enter your password.
If you need to generate a key pair on your PC. run
% ssh-keygen -t rsa
Accept the default location.
You will be prompted for a passphrase, and asked to confirm it. If you enter an empty string, you can use your key to log on to the Pi without further interaction.
So can anyone else who gains access to your PC account, so use this option with care!
OpenSSH will create a pair of files in your .ssh directory – a private key which you must keep secret, and a public key which you can transfer to other computers.
To transfer your public key to the the RPi, on your PC run:
# On Linux
% ssh-copy-id nat@<raspi-ip>
# On OSX
% cat ~/.ssh/id_rsa.pub | ssh nat@<raspi-ip>
"umask 077; mkdir -p .ssh ; cat >> .ssh/authorized_keys"
and after one final prompt you won’t be prompted for your Pi password when using ssh or sshfs.
When you’re finished
When you’ve finished, unmount the directory using fusermount -u:
% fusermount -u quick2wire