Last active
May 21, 2025 15:00
-
-
Save ddrown/7fa3f0c469dae49cc45bd57e3105fa52 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.ssh/config | |
host server | |
setenv SSH_CLIENT_NAME=laptop | |
hostname server.example.com |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/ssh/sshd_config.d/env.conf | |
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES | |
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT | |
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE | |
AcceptEnv XMODIFIERS | |
AcceptEnv SSH_CLIENT_NAME |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import subprocess | |
import re | |
from pathlib import Path | |
import os | |
def mosh_client(line, pid): | |
envfile = Path(f"/proc/{pid}/environ") | |
if not os.access(envfile, os.R_OK): | |
print(line) | |
return | |
with open(envfile, "r") as envfd: | |
envdata = envfd.read() | |
settings = envdata.split("\0") | |
ssh_client_name = "??" | |
for setting in settings: | |
ssh_client = re.match("^SSH_CLIENT_NAME=(.*)", setting) | |
if ssh_client: | |
ssh_client_name = ssh_client[1] | |
print(f"{line} {ssh_client_name}") | |
who_output = subprocess.run(["who"], capture_output=True) | |
lines = who_output.stdout.decode("utf-8").split("\n") | |
for line in lines: | |
mosh = re.match(".*mosh \[([0-9]+)\]", line) | |
if mosh: | |
mosh_client(line, mosh[1]) | |
elif len(line) > 0: | |
print(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment