$SSH_CLIENT
OR
$SSH_CONNECTION
(or any other environment variables) which gets set when the user logs in. Then process it using the user login script.
Extract the IP:
$ echo $SSH_CLIENT | awk ‘{ print $1}’
1.2.3.4
$ echo $SSH_CONNECTION | awk ‘{print $1}’
1.2.3.4
reference: https://stackoverflow.com/questions/996231/find-the-ip-address-of-the-client-in-an-ssh-session
[linux] 取得 ssh 時的 ip
分類:linux