LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-06-2006, 08:47 AM   #1
Murali Mohan
LQ Newbie
 
Registered: May 2006
Posts: 3

Rep: Reputation: 0
How to get SSH connection info programatically?


User U1 on machine M1 logged onto machine M2 via ssh as user U2 and running a Perl program P2.
Within the perl program P2, will I be able to know that U1 on M1 is ruuning this program? If so, how?
Thanks,
Murali Mohan.
 
Old 05-06-2006, 09:00 AM   #2
ioerror
Member
 
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 34
ssh sets a few environment variables SSH_CLIENT, SSH_CONNECTION and a few others, you could maybe use one/some of those. SSH_CONNECTION consists of "source_ip source_port dest_ip dest_port", SSH_CLIENT has "source_ip source_port dest_port" so either of those should suffice to determine M1, but I can't think of any way offhand to determine which user (U1) initiated the session (other than maybe logging in from M2 to M1 and running ps).
 
Old 05-06-2006, 09:30 AM   #3
Murali Mohan
LQ Newbie
 
Registered: May 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you for you response..
I tried, but, I notice that these variables, SSH_CLIENT, SSH_CONNECTION and SSH_TTY are set on M1. The program that is being invoked is running on M2. Will that program be able to access these variables?
 
Old 05-06-2006, 10:16 AM   #4
ioerror
Member
 
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 34
They should be set on the remote side (M2). At least, they are when I log in remotely. This:

Code:
ssh <M2> echo \$SSH_CONNECTION
should print the ip addresses and ports. If they aren't printed, then I don't know why, it works for me?
 
Old 05-17-2006, 06:34 PM   #5
Murali Mohan
LQ Newbie
 
Registered: May 2006
Posts: 3

Original Poster
Rep: Reputation: 0
I am sorry I didnot notice well. It was giving me the remote IP
Next, how can I get the remote user?
 
Old 05-19-2006, 03:52 AM   #6
ioerror
Member
 
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 34
That is less straightforward, I don't think ssh provides that information, so there is no way to get it directly. Probably the easiest way would be to wrap ssh in a shell script that set a REMOTE_USER variable.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Background a process (programatically) podollb Linux - Software 1 11-03-2005 06:28 AM
Basic Samba connection info... redrobin77 Linux - Networking 2 09-20-2005 11:01 AM
a command for info about my IP and my connection Xavius Linux - Newbie 1 04-06-2004 03:21 AM
change wallpaper in kde programatically verstapp Linux - Newbie 6 03-30-2004 07:19 AM
Programatically downloading file. ugenn Linux - General 1 05-13-2002 09:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 01:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration