4

I have two users who need to use the same login due to an application restriction.

These users have vastly different opinions on what a shell prompt should look like. One of them even insists on modifying the color palate. This has resulted in a .bashrc PS1 dispute. I've given them scripts to set their own preferences but... let's just say that it's complicated.

Fortunately, they both connect from locations with known IP addresses. Is there a way that I can incorporate the user's remote IP address into a conditional and thus give both of them what they want without any additional steps on their end? They're connecting via ssh.

Spiff
  • 110,156

2 Answers2

5

From the manual of OpenSSH SSH client (man 1 ssh):

ENVIRONMENT
ssh will normally set the following environment variables:

[…]

SSH_CONNECTION Identifies the client and server ends of the connection. The variable contains four space-separated values: client IP address, client port number, server IP address, and server port number.

[…]

In .bashrc you should do like:

case "${SSH_CONNECTION%% *}" in
1.2.3.4|1.2.3.5 )
   PS1=…
   ;;
2.2.7.* )
   PS1=…
   ;;
# add support for more users if needed
esac

or like

if [ "${SSH_CONNECTION%% *}" = "1.2.3.4" ]; then
   PS1=…
else
   PS1=…
fi
0

If they're logging in with ssh using keys, you can do something like:

myip=`grep 'Accepted publickey for bozo' /var/log/auth.log | tail -1 | awk '{print $11}'`

and then compare $myip. If they're using passwords, modify accordingly. (Also modify if for some reason their username isn't bozo.)

(This should work for Ubuntu and other Debian variants; the auth log file location/name and exact format may vary with other flavors.)

ras
  • 1