Ubuntu: How to get client ip in an ssh session?



Question:

I have a /etc/ssh/sshrc file that emails me after every every SSH login. It uses $SSH_CLIENT to get the IP address, but with all the methods I try, I get that the IP is ::1. How can I get the real IP of an ssh client and why is it giving me the IP of localhost? I just realized the problem was caused by sslh, which forwards all ssh connections from port 443 to 22. Is there any way to fix this?


Solution:1

With command

sudo netstat -at | grep ssh  

you can see who is connected on SSH server. This can write to some .log file

sudo netstat -at | grep ssh >> ssh.log  

Or you can create script, something like this

nano ssh.sh  

or give some diferent name

#!/bin/bash  date >> ssh.log  netstat -at | grep ssh >> ssh.log  

give chmod 777. This script will first write date and ssh sessions This log cen send to email ....


Solution:2

Thank you for everyone that helped. I found that the problem was sslh, and the solution was using transparent forwarding.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »