Synology NAS uses the key for password-free authentication SSH access. I tried the setting but couldn't get in. So I tried other methods and found this PowerShell plug-in Posh-SSH to achieve https://github.com/darkoperator/Posh-SSH, The specific installation steps are as follows.
View Powell version command: Get-Host | Select-Object Version
Posh-SSH requires 5.1 or 7.x or above, and powershell needs to be upgraded.
The machine is server2012 R2 version, download link:
After installation, you will be asked to restart the system, check the version after completion
Try to install according to the command prompt on GIT: Install-Module -Name Posh-SSH
An error message pops up: PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories.
Use the following 2 commands to solve this problem
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet
Run the command again: Install-Module -Name Posh-SSH
The installation is complete, and then you can write PowerShell script operations
$Password = "abcd1234562"
$User = "admin"
$ComputerName = "192.168.1.1"
$Command = "ls"
$secpasswd = ConvertTo-SecureString $Password -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential($User, $secpasswd)
$SessionID = New-SSHSession -ComputerName $ComputerName -Credential $Credentials #Connect Over SSH
Invoke-SSHCommand -Index $sessionid.sessionid -Command $Command # Invoke Command Over SSH
###If ssh is not using the standard 22 port, you can specify it here
$SessionID = New-SSHSession -ComputerName $ComputerName -Credential $Credentials -Port 1234
###Or execute the sh script and specify it at the Command: here is a way to find that sh shellscript cannot be executed, such as "sh /tmp/test.sh"