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,351
  • 10
  • 85
  • 161
xaander1
  • 221
  • 2
  • 11
  • 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,351
  • 10
  • 85
  • 161
  • when i run `xander@ariella:~$scp xander@ariella:stunnel.pem ~/Desktop -P 2222` i get *2222: No such file or directory* – xaander1 Oct 23 '19 at 18:10
  • Hi, @xaander1, this is my fault, the option must be at the beginning of the command - see the updated answer. – pa4080 Oct 23 '19 at 18:13
  • now am getting *ssh: connect to host ariella port 2222: Connection refused* – xaander1 Oct 23 '19 at 18:16
  • @xaander1, I've updated the answer once again :) – pa4080 Oct 23 '19 at 18:24
  • still giving `ssh: connect to host 127.0.0.1 port 2222: Connection refused` have you tried it practically. – xaander1 Oct 23 '19 at 18:29
  • Of course, I have, @xaander1 :) The difference is I'm using VM with bridged connection that gets its IP from my routers DHCP... – pa4080 Oct 23 '19 at 18:40
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/100212/discussion-between-xaander1-and-pa4080). – xaander1 Oct 23 '19 at 18:43