bdsh - Whitelist Restricted Shell

29-06-2013 | Remy van Elst

Table of Contents

bdsh is a shell where you whitelist commands and only those commands can be executed. Either via ssh, as an interactive shell or launched with commands. Logs everything and escapes "dangerous" characters.

bdsh stands for Boa Diminish SHell. You can probably guess why. It might have to to with snakes and restricting users, no pun intended.

What is the reason you wrote bdsh?

Sometimes sysadmins are forced to work with insecure systems or badly written applications. Critical systems working with a push model instead of a pull model, things that use ssh and break when stuff changes or users that need to be audit trailed.

I couldn't find an easy way to set a shell for a user that both logs and is configurable via a whitelist. I tried scripts in authorized_keys but then things scp and sftp break. bdsh tries to solve that and is fairly successful in that.


  • Python 2.6+
    • Python 3 is supported!

bdsh is tested on Ubuntu, CentOS, OpenSUSE and Debian all with Python 2.7 or above.


Either from github:

git clone

Or from this website:



  • Clone the git repo &&&& cd in
  • Install bdsh sytemwide
    • sudo cp /usr/bin/bdsh
    • sudo chmod +x /usr/bin/bdsh
  • Edit and place whitelist
    • vi example_whitelist.conf &&&& sudo cp example_whitelist.conf /etc/bdsh_whitelist.conf
  • Edit /etc/shells and add /usr/bin/bdsh
  • Set the shell for the user, either via:
    • sudo chsh -s /usr/bin/bdsh $USERNAME
    • or
    • vi /etc/passwd



Put these two lines in the whitelist file:


Note that you might have to change scp to /usr/bin/scp.


bdsh only checks if the command is whitelisted, not the arguments. So if you allow ls, you also allow ls -la, and ls -d and such.

bdsh is not 100% safe, but it does provide a layer of security.

Read this article about restriced shells:

Don't change the "Dangerous Characters" array, if you for example remove the && then you can do something like this: ssh user@host "ls &&&& perl -e 'exec "/bin/bash"'".

It does try its best to catch restriction-escaping:

Jun 29 17:41:07 localhost bdsh: [RESTRICTED SHELL]: user "testshell" executed vim
Jun 29 17:41:11 localhost bdsh: [RESTRICTED SHELL]: user "testshell" NOT allowed for /usr/bin/bdsh -c bash

See Also

Another way to restrict ssh, written by me: The github page:

Tags: bash, python, restricted, sh, shell,