Score:0

sshrc script no longer working

aq flag

I have an /etc/ssh/sshrc script that I have used in the past and it has worked fine. chmod is 755

#!/bin/bash

ip=`echo $SSH_CONNECTION | cut -d " " -f 1`

if [[ $ip == 192.168.1.* ]] || [[ $ip == 127.0.0.1 ]] ;
then
  exit
fi

echo "User $USER just logged in from $ip" | sendEmail -t recipient@example.com -f sender@example.com -u 'SSH login detected' > /dev/null

I recently upgraded to Ubuntu 22.04 and I now get this error:

/etc/ssh/sshrc: 5: [[: not found

I then found a similar script https://gist.github.com/mplinuxgeek/f08b91d2236b742f19c63579cd727167 and I get the same error on the if statement with this one. Any ideas what is wrong here? I know it worked in Ubuntu 18.04. I'm not sure if it worked in Ubuntu 20.04 since I have not utilized the ssh server much since covid.

EDIT: It does appear that dash is being run.

$ ls -al /bin/sh
lrwxrwxrwx 1 root root 4 Feb  8 19:08 /bin/sh -> dash
us flag
Are you sure `/bin/bash` is really bash? Confirm with `ls -l /bin/bash`. Also, try running `bash /etc/ssh/sshrc` to see if you still get the error. FYI, backticks are deprecated and you should use `IP=$(...)` for the assignment. You might also want to put 192.168.1.* in single-quotes to make sure it is never expanded.
hr flag
`man sshd` suggests that "sh(1) runs it" (implying that the shebang is ignored?) so it would suggest that /bin/sh was symlinked to bash on your previous system whereas it is now symlinked to dash (which doesn't support the `[[ ]]` extended test syntax)
aq flag
I actually had this content on my Ubuntu 20 Pi: `/bin/bash /home/rtaft/bin/sshrc` which explains how I was able to get it working. The Pi wasn't working yesterday so I couldn't just look at the difference.
Score:1
vn flag

I think steeldrivers comment is correct, in which case you should replace the double brackets with single ones (and also the double equal signs):

#!/bin/sh

ip=$( echo $SSH_CONNECTION | cut -d " " -f 1 )

if [ $ip = 192.168.1.* ] || [ $ip = 127.0.0.1 ] ;
then
  exit
fi

echo "User $USER just logged in from $ip" | sendEmail -t recipient@example.com -f sender@example.com -u 'SSH login detected' > /dev/
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.