Monday, 8 September 2014

Backing up to FreeNAS with SSH, CIFS share

I wanted to have a backup of some files in our infrastructure on a CIFS share that can be both accessible on Windows and Linux. 

However I had some issues: “cannot chmod target file”. because I used mc on my mounted share. So I used SSH for my first copy, where I had another issue on FreeNAS - the service did not start from the webgui and I started investigating:

[root@itsoft ~]# /usr/sbin/sshd                                                 
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_dsa_key                              
Could not load host key: /etc/ssh/ssh_host_ecdsa_key                            
Disabling protocol version 2. Could not load host key                           
sshd: no hostkeys available -- exiting.

Well that's not that bad lets generate the keys and then turn on the service:

ssh-keygen -t rsa
ssh-keygen -t dsa
ssh-keygen -t ecdsa

On the host you want to copy from you can execute something similar:

scp -r /some/local/path user1@destination:/some/remote/path


And that's it about the SSH.

Now back to the share on FreeNAS. I had my share configured as this:






On the host you want to copy from (in my case ubuntu server) you will need this:
sudo apt-get install cifs-utils

In fstab add:
//<ip>/directory /mount/point cifs defaults,user=,password= 0 0

Notice here the user and password - I have left it blank so it can write as nobody. So where did the problem with mc come from? Well it is quite simple actually when you press F5, untick the option “Preserve attributes“.

References:

http://technology.mattrude.com/2010/01/enable-ssh-no-password-authorization-with-freenas/
http://knowledgelayer.softlayer.com/procedure/mount-nas-storage-linux
http://stackoverflow.com/questions/13451974/how-to-execute-a-scp-command-with-the-user-name-and-password-in-one-line
http://askubuntu.com/questions/313093/how-do-i-mount-a-cifs-share-via-fstab-and-give-full-rw-to-guest