Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PSCP file from Windows to Linux using private/public keys

I can transfer file using PSCP:

C:\>pscp -pw <password> -r -p <path of the file>  user@Server:<path file to stored>

But not using the public/private key.

Steps followed:

  1. Generate public and private keys using PuTTYgen.

  2. Copy the public key to authorized_keys of Remote Server

  3. Save the private key to key.ppk in Windows server

  4. Then

    C:\>pscp -i privatekey pathofthefile user@server:pathfiletostored
    

It gives "Fatal: Network error: Connection refused"

Can someone please help?

like image 635
user3131119 Avatar asked Feb 09 '16 12:02

user3131119


People also ask

How do I transfer files using Pscp?

To copy a file or files using PSCP, open a command window and change to the directory in which you saved pscp.exe. Then type pscp, followed by the path that identifies the files to copy and the target directory, as in this example. Press Enter, then follow your usual authentication procedures to execute the transfer.


1 Answers

Use the following code:

C:\>pscp -i "path\of\the\privatekey\privatekey.ppk" C:\temp\example_file.txt user@server:/path/file/to/be/stored

Note the quotes for the private key path and the private key should be in .ppk format.

The connection refused error may also be due to the wrong port. In that case, you need to mention the correct port by the following code :

C:\>pscp -i "path\of\the\privatekey\privatekey.ppk" -P 8022 C:\temp\example_file.txt user@server:path/file/to/be/stored

Note that 8022 is the port number and the P is uppercase. Hope this helps.

like image 91
Gokul Anugrah Avatar answered Oct 06 '22 06:10

Gokul Anugrah