Boot script to set ssh keyfile and disable clear password login

MyCloud Gen 2 (firmware 2.x)

The goal is to

  1. use ssh keyfile
  2. disable clear password login

After some research in this forum, I am planning to make following changes, not very familiar with WD OS, in order not to brick the NAS, can any experts advise if the changes will work or not? Thanks in advance!

Based on this post:

I will add following to /usr/local/config/config.xml

<name id="10">user_boot_script</name>

and

<user_boot_script>                                          
    <count>1</count>   
    <item id="1">
        <method>3</method>
        <1>*</1>
        <2>*</2>
        <3>*</3>                   
        <4>*</4>                       
        <5>*</5>
        <run>/shares/Public/backup/user-boot-script.sh &amp;</run>
    </item>                            
</user_boot_script>

User script:

#! /bin/sh

CONFIG=/etc/ssh/sshd_config
LOCKFILE=/tmp/user-boot-script
BACKUP=/shares/Public/backup

# only run once
if [ -f $LOCKFILE ]; then exit 0
fi
touch $LOCKFILE

# execute commands 5mins after reboot
sleep 5m

# copy backup .ssh/id_dsa to home folder
cp -r $BACKUP/.ssh $HOME/

# disable clear password login
sed -ir 's/(PasswordAuthentication yes)/PasswordAuthentication no/' $CONFIG

# restart sshd
kill -HUP `cat /var/run/sshd.pid`

My questions:

  1. Will above work? I just hope I don’t need to do 40s factory reset…
  2. Since the user cronjob runs every min, even it quits immediately because of the lock file, will it still wake up NAS from sleep?

Thanks

Suggest that you do a check on your backed up .ssh folder. That way you dont nuke it on reboot.

i can verify the commands in the script one by one from command line, that’s not the problem.

my worry is, even the script works fine, i am not sure if it will run without issue when it is hooked on config.xml, which may cause MyCloud fails to boot?

I was meaning, you need to check for existence at destination before blindly copying the file. :stuck_out_tongue:
EG,

If not exist at destination:
  do copy
else
   If exist at destination
      rename destination
      do copy
   end if
end if 

That way you dont blast your backup.

I see. I think the root home folder is always wiped up after reboot.

Anyway thanks for the suggestion, it is good to check the existence.