asyncssh
asyncssh copied to clipboard
Not all env vars set
Slightly extending the example from the docs:
async def run_client() -> None:
async with asyncssh.connect('localhost', password="gh^ds&8e") as conn:
env = {
'LANG': "AAA",
'LC_COLLATE': "BBB",
'FOO': "BAR",
}
result = await conn.run('env', env=env)
print("AAA" in result.stdout)
print("BBB" in result.stdout)
print("BAR" in result.stdout)
try:
asyncio.get_event_loop().run_until_complete(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
This outputs:
True
True
False
Any reason the extra env var FOO
is not set?
SSH servers typically limit the set of environment variables they'll pass through from the client request. So, even though AsyncSSH will pass everything you give it to the server, the server may not pass all of those variables on to the command you are running. The only exception is TERM (terminal type). Everything else is typically disabled by default. There's a note about this in the AsyncSSH documentations. Scroll down on https://asyncssh.readthedocs.io/en/latest/api.html#asyncssh.SSHClientConnectionOptions until you get into the entry for "env" to see a note about this.
On OpenSSH as a server, it much be configured with "AcceptEnv" to accept any environment variables other than TERM from SSH clients. Looking at a Linux box I have here, the default is:
AcceptEnv LANG LC_*
This would explain what you saw.
For what it's worth, macOS doesn't seem to include any AcceptEnv by default, so it probably would have stripped out all three of the values in your example.
Closing due to inactivity. Feel free to reopen this or open a new issue if you need anything else.