Thursday, March 24, 2011

Using BASH on the Synology DS210j

The default shell installed on the Synology NAS is "ASH", which I believe is short for "almost shell". Okay, that's not actually true, but ASH is definitely geared towards constrained environments While functional, it's pretty sparse when compared to something like BASH, which has fantastic functionality like brace-expansion and career coaching.

So, let's install BASH, because it's an aweseome shell, and installing it is super-easy. This assumes you've already bootstrapped your NAS with the IPKG installation.

First we will install the BASH package using IPKG
ipkg install bash

Next we will tell the system that we prefer BASH over ASH, thank you very much. We will do this by editing the /etc/passwd file. Be very very very careful editing this file, as if you muff it up then you might not be able to log into your system!

So, let's be super extra careful and make a back-up of the file, just in case.
cp /etc/passwd ~/just-in-case

Now we'll edit the file
vi /etc/passwd

Look for a line like this:

We want to change the end bit to point to bash, so we change "/bin/ash" to "/opt/bin/bash". When you're done it will look like this (!!see 'update' below!!):

Save the file, but DO NOT exit your ssh session! First, test our modification by attempting to log in again from another ssh window. If you cannot log in for whatever reason, then restore the file and try again
cp ~/just-in-case /etc/passwd

If you can login, then you delete the backup file and Bob's yer uncle.
rm ~/just-in-case

The man page for BASH is a fantastic wealth of information.
Read it. Know it. Love it.


As mentioned above, if you muff things up here you might end up unable to log into your Synology.  Well just that happened to me when I updated the DSM and somehow lost my bash binary.  Login attempts now result in "/opt/bin/bash: No such file or directory".

If you fall into this trap as well, you can try reseting your firmware by following these instructions.

To prevent this in the future, a user in the Synology forum suggested leaving the /etc/passwd file as-is and adding this to your .profile.  I heartily agree.

if [ -x /opt/bin/bash ]; then
  exec /opt/bin/bash

Also, you should fix the SUID permission on the "su" binary (which just links to "busybox" so you can execute fix other issues should your root user become corrupt.

Plus, if your NAS is visible to the internet, consider disabling the "root" user altogether and creating a different user for root access.  I've detailed that in this post.


  1. Typo - on line looking for, the shell is already set to bash.

  2. Nice catch, Matthew! Corrected above.

  3. You can save it without reseting
    Install this,

    Add the path to the file you want to edit, i.e.
    /etc/passwd, passwd
    /root/.profile, .profile
    and you can edit the files from this program.

  4. I had the same issue until today ... I managed to fix this thing without reinstalling or resetting .
    1 / connect with admin account .
    2 / su - root -s /bin/ash
    3 / type root pwd
    4 / fix the /etc/passwd by replacing /bin/bash to /bin/ash

    Yeeeeahhhhhh !!