DEV Community

lbonanomi
lbonanomi

Posted on

2

SSH Shibboleths

I'm a bad meeting attendee; 5 minutes into any slide deck I retreat into paranoid fantasies of network espionage. Last budget session fantasy-me needed a subtle back channel to indicate that I was operating from a compromised position, so regular me hacked-together a working prototype with bash init scripts, SSH key features, and a little-used SSH config file.

Commands in SSH keys

It's probably common knowledge that key values in the SSH authorized_keys file can be locked to a single command, so I'll just say that the regularly used SSH key for this system was altered to start with command="exec bash" to start an interactive shell.

sshrc

Hosts using the OpenSSH daemon will process a user's $HOME/.ssh/rc file before sourcing the user's shell init scripts. By default sshd will not allow environment variables to be exported, but will happily execute shell scripts, so a simple instruction to run touch $HOME/.ssh.lck was added to create a lockfile. This has the helpful side-affect of not messing with console logins.

bashrc

Last stop is to modify .bashrc to look for the ~/ssh/rc lockfile, set $PROMPT_COMMAND to execute a function for password-auth vs. ssh key-auth, and remove the lockfile.

if [[ -f .ssh.lck ]]
then
        if [[ $(ps axwww | awk '$1 == '"$$"' { print $NF }' | grep "bash") ]]
        then
                function passworded() {
                        echo "User is password-authenticated"
                        unset PROMPT_COMMAND
                }
                export PROMPT_COMMAND="passworded"
        fi

        rm .ssh.lck 2>/dev/null
else
        function keyed() {
                echo "User is SSH key-authenticated"
                unset PROMPT_COMMAND
        }
        export PROMPT_COMMAND="keyed"

        rm .ssh.lck 2>/dev/null
fi

The passworded and keyed functions should of course be tailored for your needs.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay