Network Backup Storage with NAS, rsync, ssh public key set up.
In my previous post I shared how to transfer huge files without using cloud services. Point-to-point. Today we move a step further by giving a try to a personal dropbox-like cloud service.
It is not a secret for anyone that having no backup is like playing with fire. The HDD/SSD might never die or it might be a matter of time to happen. You never know. But it is always a good idea to be prepared. As you will see in some of the videos I will share later in this post, you can have a backup with external hard drive which is pretty tedious because you should mount and unmount it. An alternative solution might be to pay some money per month/year to a cloud storage service. But this is not an option to me because I don't really like sharing my personal stuff with companies.
So a short research shows us Synology NAS (no advertisement intended here) as an option. It could be used literally for many things besides backup but this was my goal - having a backup and personal dropbox-like storage so I get rid of dropbox emails pushing me to upgrade my account so I get more storage. Don't get me wrong. It served me well for a decade already but it was time to get out of the comfort zone and find an alternative.
NAS. Network Attached Storage.
I am not good at "advertising" and explaining what it is and how it works and blah blah. That's why I will share with you all the links I found on internet that solved my problems.
First of all, here are introduction videos to get familiar with NAS.
You see, it has a lot of possibilities.
My set up:
I am on a linux machine so I want to backup a linux machine. Here is an article from Synology about how to do it:
As you have might guessed already, it is never enough and there are some real world issues.
rsync
After I waited for 1 day and a half to see the Synology Cloud Service is not backing up anything I started digging in internet for alternatives. Way before any Synology NAS solutions to exist the Administrators of servers used to use rsync.
rsync is a command line tool for transferring files from source to a destination with a lot of possibilities. Here is a video to get you familiar with rsync:
cron jobs
After setting up rsync for Synology's DSM it still wasn't automatic. To automate it to "trigger" in a specific time you should use crontab or the modern way - systemd which replaced crontab. Here are some links to get you familiar with crontab and scheduling with systemd:
SSH Public - Private key Authentication
But there is one big but. You have to be able to trigger rsync without having to provide your password. In our favor comes the asymmetric encryption or public - private key pair encryption. You have used it already if you have used Github or Gitlab. Here is a video to get familiar with it.
In order to have asymmetric encryption you need to generate public, private key pair. It sounds like a rocket science but it is not. Here is a link on how to generate it.
And here is a link how to do it properly and use a "next level" private key algorithm because RSA is considered insecure already.
But again, it seems it is not enough to make NAS working with SSH keys. Here is the solution:
Important: In the above article you should edit your sshd_config file and uncoment line `RSAAuthentication yes`. After openssh 7.4 there is no such line so the rest two lines is enough.
After you do this (which is how it should be) the NAS will still prompt you with a password. This is because of the permissions of the user's home directory. You can find the solution in the bellow's link. Check the troubleshoot section for how to change the directory permissions.
Whew!
That's all you need to have automated passwordless rsync backup.
It seems like a huge work to be done but if you don't know how to do it, you will learn A LOT! Which is the most important. ... After you detach yourself from payed cloud services and do it yourself :)
Good luck and let me know if you struggle setting it up. I struggled a lot.
Comments
Post a Comment