This will show you how to setup a SSH file server on Ubuntu 10.04 Lucid Server Edition. It will use RSSH so the user connecting will only be able to use SFTP when connecting.
Install RSSH which is a restricted SSH this will restrict the user to running commands associated with file transfers. The user will not be able to login to the server with SSH.
1 2 3 4 5 6 7 8 9 10 11 12 13
| administrator@ubuntu:~$ sudo aptitude install rssh
The following NEW packages will be installed:
rssh
0 packages upgraded, 1 newly installed, 0 to remove and 52 not upgraded.
Need to get 56.9kB of archives. After unpacking 233kB will be used.
Get:1 <a class="linkification-ext" title="Linkification: http://us.archive.ubuntu.com/ubuntu/" href="http://us.archive.ubuntu.com/ubuntu/">http://us.archive.ubuntu.com/ubuntu/</a> maverick/universe rssh amd64 2.3.2-11 [56.9kB]
Fetched 56.9kB in 0s (92.0kB/s)
Preconfiguring packages ...
Selecting previously deselected package rssh.
(Reading database ... 40526 files and directories currently installed.)
Unpacking rssh (from .../rssh_2.3.2-11_amd64.deb) ...
Processing triggers for man-db ...
Setting up rssh (2.3.2-11) ... |
Edit the rssh config file and uncomment the lines below to enable restricted access.
1 2 3 4 5 6 7
| administrator@ubuntu:~$ sudo nano /etc/rssh.conf
allowscp
allowsftp
allowcvs
allowrdist
allowrsync
allowsvnserve |
Create the directory where for the file share users to have access to with file permissions for full access. The Files folder is created inside the sshfs because the sshfs folder will be used for the home directory and will contain files such as .bash_history so the Files folder will be used as the root directory when connecting.
1
| administrator@ubuntu:~$ sudo mkdir -m 777 /sshfs |
Add a usergroup for the file share users.
1 2 3
| administrator@ubuntu:~$ sudo addgroup sshfs
Adding group `sshfs' (GID 1001) ...
Done. |
Create a user for the file share. Setting the home directory /sshfs and using restricted SSH as the shell. Change client to the user name you want.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| administrator@ubuntu:~$ sudo adduser --no-create-home --ingroup sshfs --home /sshfs --shell /usr/bin/rssh client
Adding user `client' ...
Adding new user `client' (1001) with group `sshfs' ...
Not creating home directory `/sshfs'.
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for client
Enter the new value, or press ENTER for the default
Full Name []: Client
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] |
Now on client computer install sshfs enless you prefer a different application to access to file share and make the directory where the file share will be mounted.
1 2
| administrator@client:~$ sudo aptitude install sshfs
administrator@client:~$ sudo mkdir -m 777 /media/Files |
Test the file share using the command below. Replace USERNAME and SERVER with your user name and server. If the username for the client is the same as the server the “USERNAME@” is not needed. Then if the file share works run the next command to unmount the file share.
1 2
| administrator@client:~$ sshfs USERNAME@SERVER:./Files /media/Files
administrator@client:~$ sudo umount /media/Files |
The best way to login to the file share is using a SSH Key. Using a SSH Key will allow you to mount the file share without entering a password and is much safer then entering the password. If you don’t want to use a SSH Key you can skip the stuff below. For this to work the username for your client must be the same as the one used to access the server.Open “System -> Preferences -> Passwords and Encryption Keys” open the “My Personal Keys” tab and then click “File -> New…” select “Secure Shell Key” and click “Continue”.

Then enter a password to encrypt the key. This password should be at least 12 characters.

If the “Set Up Computer for SSH Connection” comes up click “Cancel” the RSSH and different home folder prevent this from working.

After the key is created right click the key and select “Export…”

Save the file to the Desktop with “authorized_keys” as the name

Connect to the file share using the same command from early and place the authorized_keys file in the root of the file share.

On the server move the authorized_keys file to /etc and apply the permissions shown below.
1 2
| administrator@ubuntu:~$ sudo mv /sshfs/Files/authorized_keys /etc
administrator@ubuntu:~$ sudo chmod 700 /etc/authorized_keys |
Edit the sshd_config and add the line shown below to the end of the config file. This needs to be changed because the home folder is different then the default. Then restart the SSH server.
1 2 3
| administrator@ubuntu:~$ sudo nano /etc/ssh/sshd_config
AuthorizedKeysFile /etc/authorized_keys
administrator@ubuntu:~$ sudo /etc/init.d/ssh restart |
Disconnect from the file share and attempt to connect to it again it should ask you to decrpyt the ssh key and then it should connect to the file share without asking for a password. If it works disconnect from the file share.
1 2
| administrator@client:~$ sshfs USERNAME@SERVER:./Files /media/Files
administrator@client:~$ sudo umount /media/Files |
To get the file share to mount when the computer starts edit the fstab file and add the line shown below to the end of the file. Replace USERNAME and SERVER with the username and server IP address. Then enter the last command to mount the file share it should mount without asking for a password if you setup the ssh key.
1 2 3
| administrator@client:~$ sudo nano /etc/fstab
sshfs#USERNAME@SERVER:./Files /media/Files fuse user,noauto 0 0
administrator@client:~$ sudo mount -a |