EX4100 Public Key auth over SSH, changes killed on REBOOT

Technically it IS doable what you are trying to do. In fact, I have been doing just that since last year shortly after my purchase of the EX2 model. There are two ways to do this - the painful manual way - or the automated way but that comes with a much harder obstacle to overcome.

So here’s the problem. The way all the My Cloud EX and Mirror products work is that at boot time they discard everything in the /home and /etc directories - where the user accts and configs are kept…and they rebuild them from the firmware that permanently resides in the flash memory. Because of this, all user accts that you used to store the keys are wiped clean - as you have discovered.

So one painful way to work around the problem is to make use of a small directory where WD saves its configs (& logs) during reboots - and that directory is /usr/local/config. What you can do is create a new directory under there - let’s call it UserHomesBackup (that’s what I call it in mine). Now, after you have setup all the user’s SSH keys in their home’s .ssh directories, you need to copy the entire user directory (not just the .ssh directory) using the cp -p command into that UserHomesBackup directory. The -p switch copies the crucial permissions of files and folders, along with the timestamps. Now, after you reboot you can simply cp -p back every directory from that backup directory to /home directory - and your SSH key-based authentication will work again. But yes, the big downside to this workaround is that you need to copy those directories back after a reboot every time. The other thing I’d caution about is that the /usr/local/config directory is mounted on a very small space (filesystem) - on my EX2 it is 12.2 MB (you can find out yours by running ‘df -h /usr/local/config’ command)…which is still quite good size for storing all types of config files - but not meant to store too much files or many big files…but it is okay for storing a bunch of users’ home directories with their .ssh folders.

So the more difficult thing for many is to automate this process. If you know shell scripting and can follow instructions on how to compile code, you can take WD’s firmware source code that they make available under GPL license and compile your own firmware after making a couple small tweaks to their startup script. Basically you’d be baking in that copy of the users’ home directories back to /home on restart. In order to do so, you MUST change the system_init script that’s in /usr/local/modules/script/ directory. That system_init runs during boot time - but that script cannot be edited since it runs off of the flash memory. So the only way to tweak that is to download the source code from WD’s site, modify that init script and then compile the firmware…and finally load the firmware. Once you have loaded the firmware, you will now automatically have those user directories copied back to /home on reboot. But of course, this requires a good comfort level with Linux/Unix and the acceptance that doing this voids your device’s warranty. But I have been doing this for 20 months now and have added many customizations to the firmware - from SSH logging to SFTP logging to log archiving to many, many other features I needed, all baked into my custom modded firmware. Here’s my post from April 2014 to demo that SFTP by a non-root user (using SSH key) → SFTP possible on EX2

1 Like