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.
Follow the instructions given by Microsoft for the installation and configuration of the service: OpenSSH Install FirstUse.
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.
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 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!
Write the following in the terminal or in a script file:
ssh [user]@[hostname] [command]
- Shutdown the computer in 5 seconds:
shutdown /s /t 5
- Leave command suggestions in the comments!