2

I am trying to transfer a file from my Ubuntu Server 18.04 installed in VirtualBox to my local machine, but I can't get it work.

The network in place is NAT, in VirtualBox I have set port forwarding.

*Name*      *Protocol*  *Host IP*   *Host port*     *Guest IP*   *Guest port*
ssh           TCP                    2222                           22

To connect to my server I'm using ssh xander@127.0.0.1 -p 2222. However I'm not able to transfer a file from the VirtualBox instance to my local machine.

scp user@remotehost:/file/to/copy /local/destination doesn't work I have tried several times.

I have tried following this stackoverflow guide for NAT firewall based machines but whenever I ran this command with my credentials ssh ComputerBUser@ComputerB -R 2222:localhost:22 I get Bad port '2222:localhost:22' so I cant do much.

pa4080
  • 29,831
xaander1
  • 221
  • Did you install openssh-server? If you did not install openssh-server on the "remote" host then you will not be able to use ssh, scp, sftp, or rsync to it because they all use ssh. – Gordster Oct 23 '19 at 18:04
  • yes openssh-server is installed..i have tried using scp no avail – xaander1 Oct 23 '19 at 18:24

1 Answers1

0

To connect to my server I'm using ssh xander@127.0.0.1 -p 2222

Within SCP the port must be provided too - note here the port option is capital -P, and this option must be placed at the beginning of the command:

scp -P 2222 xander@127.0.0.1:/file/to/copy /local/destination/

IMO, for such tasks rsync is better, faster and robust (more explanations):

rsync -e 'ssh -p 2222' --progress user@remotehost:/file/to/copy /local/destination/

At all, I would prefer setup bridged connection for the virtual machine, thus it will have its own IP address in my local network


In addition I would advice you to setup ssh key based authentication and .ssh/config file - here is a short list with references about this:

pa4080
  • 29,831