views:

163

answers:

1

I want to map users (that ssh to server) to emails. In csh you have defined $REMOTEHOST variable that contains PC name from remote host. In bash, no environment variable is defined. Is there any way to get some info about connected user (except from SSH_CLIENT which gives IP and PORT)

Note that I'm using sshd and bash.

A: 

No. The only information you can obtain are user, host and port.

You can simply grep the auth.log for ssh sessions.

$ grep sshd /var/log/auth.log | grep Accepted
Sep 11 12:53:54 lenny sshd[2686]: Accepted password for cb from 127.0.0.1 port 33343 ssh2

I guess you can map usernames to email addresses.

You can simply add a command to /etc/ssh/sshrc which uses the $USER variable ;) E.g.

#!/bin/bash 
echo $USER
echo $SSH_CLIENT
tuergeist
Host? what variable holds hostname?
iElectric
I did not wrote hostname, I wrote host. I mean IP address. It may be possible to resolve a name to this address.
tuergeist
I wonder how does zsh obtain this information. Is it possible to know which public key was used?
iElectric
You shall specify what exactly you want. IMHO the ssh server knowns the used key (if used), username and the ip/port of the "calling" host.
tuergeist
Nice, do you know a way to get pubkey used? That would solve my problem
iElectric
I checked paramiko API, you can only get public key by hostname, that's not really the best solution, I bet one can get currently used public key from ssh session.
iElectric
Hi again, which app shall know the information (user, ip..)? the bash runned by the client or a server side app? For what purpose do you use paramiko? You haven't told anything about python!
tuergeist
I just want to log what users logged in to a server. Thus, I want to know what pubkey was used to map it to email address and send notification about the login (and if user didn't login, he would notice the email and this intrusion). This can be done by bash or run through python. Doesn't really matter.
iElectric
I updated my answer
tuergeist
That's USER on server. Hmmm, actually I can use USER defined variable and make sure each user on server has it's own login. Then just map that USER to an email. Well, you didn't directly solve my question but managed to make me think through it. Thanks!
iElectric
Hmm. Every user shall have its own login, otherwise you have a security problem.
tuergeist
Agreed, it should have been like that in the first place.
iElectric