Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoilomora/ece289dc9ca7a2b8dfb46714897ea8ce to your computer and use it in GitHub Desktop.
Save zoilomora/ece289dc9ca7a2b8dfb46714897ea8ce to your computer and use it in GitHub Desktop.
Run commands in Windows 10 from Linux

Run commands in Windows 10 from Linux

In many cases, it can be very useful to send a command to a Windows from Linux. In my case, I was given this need when trying to shutdown a computer remotely via command line and then integrate said command into Node-RED.

Take these simple steps and you can get them done quickly.

Install OpenSSH natively on Windows 10 with PowerShell

Follow the instructions given by Microsoft for the installation and configuration of the service: OpenSSH Install FirstUse.

Configure OpenSSH to accept Public Key Authentication.

Open %ProgramData%\ssh\sshd_config file and make the following changes:

  • Uncomment the line:

    PubkeyAuthentication yes
    
  • Comment the final lines:

    # Match Group administrators
    #        AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
    

Now restart the OpenSSH SSH Server service for the changes to take effect.

Generate RSA key on Linux

Many of you may have done this step in the past. If so, skip it.

To generate a RSA key on your Linux computer it is only necessary to execute the ssh-keygen -t rsa -C "Comment" command.

Two files will be generated:

~/.ssh/id_rsa       # Private key
~/.ssh/id_rsa.pub   # Public key

Copy the Public Key in Windows

Copy the content of the file ~/.ssh/id_rsa.pub to a new file %USERPROFILE%\.ssh\authorized_keys on Windows.

Now you should be able to connect without password!

Send command over SSH

Write the following in the terminal or in a script file:

ssh [user]@[hostname] [command]

Suggested commands

  • Shutdown the computer in 5 seconds: shutdown /s /t 5
  • Leave command suggestions in the comments!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment