I'm trying to get basic informations on my local machine from ssh connections. The purpose here is to get the current user, hostname, current working directory in my tmux status bar.
I've enabled ControlMaster in my ~/.ssh/config:
Host *
ControlMaster auto
ControlPath ~/.ssh/socket-%r@%h:%p
Now, I've managed to get the ControlPath from a homemade tmux plugin and I can send commands through the socket:
echo $(ssh -S ~/.ssh/socket-$user@$host:$port $host "$command")
This is working fine to get the remote hostname and the user. The issue is that when I change my remote user, whoami is still returning the user that was used to log in.
For example with whoami (~ is local, > is executed on the ssh session):
~ ssh soyuka@host
> whoami
soyuka
~ ssh -S ~/.ssh/socket-soyuka@host:22 host whoami
soyuka
> sudo -s
> whoami
root
~ ssh -S ~/.ssh/socket-soyuka@host:22 host whoami
soyuka #Here I want to get root because the remote user is now root
For example with pwd (~ is local, > is executed on the ssh session):
~ ssh soyuka@host
~ ssh -S ~/.ssh/socket-soyuka@host:22 host pwd
/home/soyuka
> cd downloads
> pwd
/home/soyuka/downloads
~ ssh -S ~/.ssh/socket-soyuka@host:22 host pwd
/home/soyuka #Here I want to get /home/soyuka/downloads
Is this possible somehow to execute the command on the current ssh session by it's socket?
whoamibut it's not clear why "returning the user that was used to log in" is not what you want and what it is that you expect instead; (2) I don't see the problem with yourpwd-themed command transcript (which seems to have nothing to do withwhoami) — are you expecting that changing the localpwdwould also somehow change your remote default/home directory? I don't follow.