Windows 10 has built-in support for Linux-like commands such as ssh and scp, which allows us to conveniently use a linux-like workflow to write daily code resource deployment and maintenance work into scripts (batch processing).
Both ssh and scp have the -i parameter. You can remotely log in to the Linux or Windows operating system by specifying a private key file location, but it will be more troublesome to specify the private key address with the -i parameter every time you use the command . We can also use the ssh-add method to add the private key file to the cache, so that if the asymmetric encryption key pair remains unchanged in the future, you can directly operate remotely without entering a password or private key file.
This operation needs to enable the ssh-agent service first. This service is disabled by default in my windows10, so you need to set it to auto in powershell and start it:
PS C:\windows\system32> set-service -name ssh-agent -startuptype auto
PS C:\windows\system32> get-service ssh-agent
Status Name DisplayName
—— —- ———–
Stopped ssh-agent OpenSSH Authentication Agent
PS C: \windows\system32> start-service ssh-agent
PS C:\windows\system32>
My windows username is fancy. Suppose I put the private key file in c: \windows\user\fancy\key
Just add the private key like this:
ssh-add c:\windows\user\fancy\key< /pre>
You can also rename the secret key file to
identity
or
id_rsa
In ~/.ssh/ (that is, c:\users\fancy\.ssh\)
Then directly ssh-add this will automatically add these private key files to the cache, so you don’t have to every time Use the -i parameter.
scp also uses the same -i parameter, and shares the secret key cache with the above operation
Then we can use scp to copy the script file to the remote server, and then use ssh in the remote Execute on the server to realize the scripted operation of the remote server.
OK For more books on linux server operation, there are:
powershell ssh-agent cannot work: https://www.cnblogs.com/crb912/p/9987590 .html
PS C:\windows\system32> set-service -name ssh-agent -startuptype auto
PS C:\windows\system32> get-service ssh -agent
Status Name DisplayName
------ ---- -----------
Stopped ssh-agent OpenSSH Authentication Agent
PS C:\windows\system32> start-service ssh-agent
PS C:\windows\system32>
ssh-add c: \windows\user\fancy\key