bash - How to detect the OS type of a SSH client from the remote OS

08
2014-07
  • Bohr

    If I am using PuTTY from Windows to SSH to a remote OS, how do I detect what OS the SSH client is running on, from within the remote OS?

    I think this is probably impossible. Merely the terminal type of a SSH client is difficult to detect.

  • Answers
    Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

    Related Question

    utf 8 - UTF-8 Not Working in PuTTY when using SSH Remote command
  • Navarr

    So. I am using PuTTY to connect to a remote server that has an irssi client running for me constantly through tmux.

    Connecting to the server, and typing "tmux attach" works fine and everything works as it is supposed to. Unicode characters show up just fine.

    However, if I instead set a "Remote command" in the Connection -> SSH options of "tmux attach." Tmux attaches and then Unicode doesn't work.

    I assume this might have something to do with the system terminal variable, but I have no idea.

    Any ideas on how to fix?


  • Related Answers
  • scicalculator

    hmmm ... I just realized this can be made much simpler. You said that you can perfrom the following tasks

    1. connect to the server normally
    2. attach tmux
    3. run irssi/other-things with no unicode bugs.

    If you can connect to the shell of your server, why not add tmux attach to your .*rc file? If you would like to attach to tmux most times you connect to the server, just have the server automatically attach when you connect (every time).

    Using some putty-specific connection method is a bad idea, in my opinion, because it may not work well when/if you change your method of connecting ie. if you change to a non-windows computer. So, instead of attaching to the session by using putty's "remote command", just connect regularly. If you are using a bash shell, add this to the $HOME/.bashrc file on the server:

    if [[ ! -n $TMUX ]] ; then tmux attach ; fi
    

    Then, as soon as you connect it will automatically attach to the tmux session. You can always leave tmux by using detaching:tmux detach (or you can kill every tmux session killall tmux if you want to start over).

    Of course, if you like, you can then begin to think of a more complex tmux attachment script that creates a custom-new-session OR attaches. Personally, every time I open a terminal, it launches a tmux session script (113 lines long), which sets it up just like I like it ... or it attaches if the session already exists.