I try to send a file from a Windows 2012 server to a Linux server using a script.
For that I have tested the following module: SSH-NET Librairy because if it is true ssh is not implemented natively in powershell. The trouble is that I manage to connect in my linux server has powershelle entering my login and password. But whenever I généère a public private key nothing works.
Can you tell me what is the method to do this kind of script?
Have you added your public key to the .ssh/authorized_keys file of the user on the Linux machine you’re trying to log into?
Please share what you already have as PowerShell script (attach as .txt file or use the code block). It is kind of difficult to help you without you sharing what you already have.
The connection with linux is ok , i have all desinstalled adn installed and it’s work. Just the scp will not work with my script :
(pre){New-SshSession -Computer 192.168.0.1 -Username test -Keyfile C:\Users\Administrateur\Documents\ssh\id_private -Scp -Sftp -Reconnect
Get-SshSession | ft -AutoSize
You’ve specified the destination path with backslash’s instead of forward-slash’s which Linux expects.
The destination path you’ve specified is not the “test” users home directory. You need to you use /home/test or give the test user access to /home/Ubuntu.
I believe SCP expects the file in the destination path like below:
I didn’t mount the Linux machine. I’ve used the New-SshSession command as you did to establish the connection with the private/public key and used any of the example commands below to send the file successfully to the Linux machine.
The Copy-Item does not work out of the box with Linux machines. The Linux machine would need to have the Samba server installed and configured correctly to allow the access via UNC path (\192.168.0.1\home\test).
You were on the right track with the SSH-Sessions module. It would be better if you would continue with getting the SSH-Sessions PowerShell module work for you.