Is there a way to get the Windows' username of the user who's connecting to a specific Unix environment, using always the same server's credentials, directly in Bash?
There is a population of N users, who may connect to M different Unix environments always using the same credentials on Unix: someusername , no password. Basically,
PMatteo.fr.company.com
". SSH
session on the Linux machine linuxMachine
, using Putty. someusername
, no password, and the user is in. Inside the Unix environment, hence using a bash command, I would like to retrieve the Windows username "Matteo".
The following command:
echo $(who am i) | cut -d "(" -f2 | cut -d ")" -f1
is showing me two kinds of outputs, depending on the machine to which I'm connected:
PMatteo.fr.company.com
45.32.4.19
), but that's fine because I get to find the machine name using the command nslookup 45.32.4.19
. Is there any way, using a Bash script, to go directly up to the Windows username? I can (pretty) easily find the machine name, so I believe that the Windows username may be stored somewhere, I just don't know how and I can't find it anywhere in the web. Does anyone have any hint? My bash version is 4.1.2(1).
From the windows username, I can always rebuild the mail address of the user. Sometimes the user launches a command that may affect other users, but since they connect (Unix-speaking) always with the same username, nobody knows who is actually performing the command. It would be nice to be able to reach them by email in case someone else wants to ask to stop what they're doing.
The simple answer is no.
You do not transfer this information to your Unix/Linux server, because you always login with the credentials of someuser
.
Because you can derive the username from the hostname of your PC, you may be able to derive the windows username, but this has a number of flaws:
What you might try is access the windows client from the Linux box. But that requires that all the clients are accessible from Linux (rdp, telnet, powers hell, ssh server or something like that, and of course authorization on Windows). Then you might look at who is logged-in at that time (and hope it is just one user).
In Putty, go to Connection->SSH->Remote command and add this,
env WINUSER=yourname bash
then connect. That should set the environment variable WINUSER
in the remote shell environment.
This assumes a trusted environment, since anyone could fake the setting when they log in.
(This might get bumped over to https://superuser.com )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.