Continuing on using the raspberry pi as
your desktop's sidekick, we will focus today on making it easier to work with, better integrated, when your desktop is Unix (Solaris, OpenIndiana), Linux, Mac OS/X or even Windows (except you wont be able to use ssh-keygen or scp - instead check the section I Got a PC? toward the end of the post).
Automating login
First thing first, we need to create a new user on the Raspberry Pi. Although the user pi is pretty cool, you dont want to have to specify the user in all the commands you will do, so we'll match it to the username on the desktop.
Let's say your username is user on your desktop (of course, if you want to have a username billybob, then replace user with billybob in the below code). You will need to connect as the pi user, then set up a new user:
ssh pi@raspberrypi
(enter your pi user password)
pi@raspberrypi ~ $ sudo useradd -d /home/user -s /bin/bash user
pi@raspberrypi ~ $ sudo mkdir /home/user
pi@raspberrypi ~ $ sudo chown user:pi /home/user
pi@raspberrypi ~ $ sudo passwd user
pi@raspberrypi ~ $ Enter new UNIX password: (type password)
pi@raspberrypi ~ $ Retype new UNIX password: (type it again)
pi@raspberrypi ~ $ passwd: password updated successfully
pi@raspberrypi ~ $ sudo cp .bashrc ../user
pi@raspberrypi ~ $ sudo cp .profile ../user
The last item we have to do is to edit the /etc/sudoers file and add our user to it ([esc] means hit the escape key):
pi@raspberrypi ~ $ sudo vi /etc/sudoers
(add the following line after going to last line and typing o)
user ALL=(ALL) NOPASSWD: ALL
[esc] :wq!
pi@raspberrypi ~ $ exit
BTW, for most people, there is too much detail (such as how to add a line in vi), but keeping in mind that there are some people in schools reading this and they just starting playing with this, I think it is well justified).
We now go back to our desktop and test that we can login as the user (no need to specify user@raspberrypi, just raspberrypi since the default is to user the desktop current user):
user@desktop ~ $ ssh raspberrypi
(enter password)
user@raspberrypi ~ $ mkdir .ssh
user@raspberrypi ~ $ exit
Now, we will generate an RSA private and public key pair. We will then copy the public key to the RPi as authorized_keys2 under the .ssh folder:
user@desktop ~ $ ssh-keygen -t rsa
(enter to accept the defaults)
user@desktop ~ $ cd .ssh
user@desktop ~ $ scp id_rsa.pub raspberrypi:.ssh/authorized_keys2
(enter password)
We will login once more on the RPi to change access:
user@desktop ~ $ ssh raspberrypi
(enter password)
user@raspberrypi ~ $ cd .ssh
user@raspberrypi ~ $ chmod go-r authorized_keys2
user@raspberrypi ~ $ exit
At last, we can now copy files using scp or login on our RPi without entering a password:
user@desktop ~ $ ssh raspberrypi
user@raspberrypi ~ $
Yeah!
SCP tasks
Getting a file
To get a file from the RPi, onto the desktop:
The file is in the /home/user directory:
user@desktop ~ $ scp raspberry:file.txt .
The file is in /home/user/directory:
user@desktop ~ $ scp raspberry:directory/file.txt .
The file is in /home/user/directory/subdirectory:
user@desktop ~ $ scp raspberry:/home/user/directory/subdirectory/file .
Putting a file
To get a file from the RPi, onto the desktop:
The file is in the /home/user directory:
user@desktop ~ $ scp raspberry:file.txt .
The file is in /home/user/directory:
user@desktop ~ $ scp raspberry:directory/file.txt .
The file is in /home/user/directory/subdirectory:
user@desktop ~ $ scp raspberry:/home/user/directory/subdirectory/file .
Action on a directory
To get or put a directory, simply use the -r flag:
user@desktop ~ $ scp -r mydir raspberry:
This will copy recursively mydir onto the server named raspberry, into the default home directory. There is a lot more flexibility to scp, so read up on it:
user@desktop ~ $ man scp
GUI access
I use OpenIndiana as a desktop, most of the time, and that OS, and most Linux versions, has a tool to connect to a server using various protocols and provide a GUI. In the case of OpenIndiana, it is the gnome tool that can be found in the menu as item "connect to server":
This will then open a Nautilus file browser:
Other Options
Another option under unix/linux to access files remotely is through sshfs, a FUSE module. It allows to mount an ssh (sftp) remote system as a local filesystem. If you need this, you are probably already know how to use it, so I wont get into details.
I got a mac?
There is no GUI option directly, Basically, using the technique above with FUSE, I've done it on my Mac using
FUSE at http://osxfuse.github.com/, then I downloaded
Macfusion.
If anybody wants a more detailed instruction, leave a comment. I dont want to spend too much time on this if no reader is using a raspberry pi as a sidekick to a Mac.
I got a PC?
To automatically login without password, you will need putty (see the
previous blog entry on this) and also
puttygen. But at the end of the day, why bother?
The OS doesn't leverage this.
Instead, get a GUI interface like
Winscp to copy files back and forth.
I use winscp all the time with Windows 7, and you can save configurations, including passwords, so this is fairly painless.