Windows equivalent of ssh - how to connect to a remote machine and access command line?

  • Questioner

    I'm having a difficult time coming up with a solution to extend a framework that was designed for *nix machines over to windows. The framework currently runs from one *nix server and ssh's out to other *nix servers and performs a bunch of different commands like checking log files, syncing files from source control, submitting logs back to source control, etc. The big piece I'm stuck on is how to connect to the remote windows machines and access the command line. The connection can be coming from another Windows machine also, it doesn't have to start from a unix machine, it can go from windows to windows instead of unix to windows.

    Here's an example of how commands are currently ran on unix systems. Something like this is in a loop that goes through a list of server names. I need to get something like this to run on windows machines.

    ssh ${user}@${server} "cd /app/app_name/logs; <export source control params>; <submit logs to source control>" >> Log.txt

    Also, I would prefer not to use a 3rd party tool (my budget is about $0). I've checked out PsExec and a couple others but it looks like you need admin access or have to pass users/pass in plain text.

  • Answers
  • Julian

    Try tunnellier from Bitvise. That is an ssh client. There's also an ssh server for connecting to a windows machine. The two enable you to make very secure connections along with more advanced things like a web proxy or port tunneling.

  • Eugene Mayevski 'EldoS Corp

    Install OpenSSH port for Windows - it's free and provides both client and server.

  • Chris Becke

    PuTTY is also a popular Windows SSH Client.

  • Related Question

    how can I pass an environment variable through an ssh command?
  • Ross Rogers

    How can I pass a value into an ssh command, such that the environment that is started on the host machine starts with a certain environment variable set to my choosing?

    EDIT: The goal is to pass the current kde desktop ( from dcop kwin KWinInterface currentDesktop ) to the new shell created so that I can pass back an nfs locations to my JEdit instance on the original server which is unique for each KDE desktop. ( Using a mechanism like emacsserver/emacsclient)

    The reason multiples ssh instances can be in flight at one time is because when I'm setting up my environment, I'm opening a bunch of different ssh instances to different machines.

  • Related Answers
  • Alois Mahdal

    The ~/.ssh/environment file can be used to set variables you want available for remote commands. You will have to enable PermitUserEnvironment in the sshd configuration.

    Variables set this way are exported to child processes, so you can:

    echo "Foo=Bar" > sshenv
    echo "Joe=37" >> sshenv
    scp sshenv user@server:~/.ssh/environment
    ssh user@server myscript

    and myscript will know that Foo is Bar and Joe is 37.

  • Robert P. Goldman

    You can pass values with a command similar to the following:

    ssh username@machine VAR=value cmd cmdargs

    You can test with:

    ssh machine VAR=hello env

    On tcsh the following seems to work:

    ssh machine "setenv VAR <value>; printenv"
  • Jayson

    There's also a horrible, horrible hack.

    If your script is consuming the variable on the remote end (i.e. you can name it whatever you want), you can abuse the locale variables. Any variable of the form LC_* will be passed on verbatim, with no requirement for configuration whatsoever.

    For example, we have a series of bastion servers at one of my clients. I hate having to connect to it, just to connect to another server... and another server... every time. I have a script that behaves just like SSH, except that it's clever.

    Basically, if LC_BOUNCE_HOSTS is set, it splits it on spaces and peels off the first host. Then it bounces through and runs the same script. On the destination node, this list is eventually empty, so it runs the command. I also have a debug mode (which is great during network troubles), which is set by LC_BOUNCE_DEBUG. Since ssh passes all of these along for me magically, I don't have to do anything other than recognize the end of the host list (which I do with a -- option).

    I feel dirty every time I use this, but it works everywhere I've tried it.

  • Georgi Kirilov

    The SendEnv option is your guy.

    ~/.ssh/config: (locally)

    SendEnv MYVAR

    /etc/ssh/sshd_config: (on the remote end)

    AcceptEnv MYVAR

    Now, whatever the value of $MYVAR locally is, it becomes available in the remote session too.
    If you login multiple times, each session will have its own copy of $MYVAR, with possibly different values.

    ~/.ssh/environment is meant for other purposes. It kind of acts as $ENV file when executing non-shell commands remotely.