Getting Connection refused error when using scp on VM

linux, scp, ssh

Solution

ssh and scp use different options for specifying the port. From the ssh man page:

[-p port]

From the scp man page:

[-P port]

scp uses capital P. Notice how your debug output says port 22 connection refused when you are trying to connect to port 2222.

Problem

I have a virtual linux build running on qemu (It runs drop bear as ssh client.) and I am trying to copy some modules I wrote to it using scp using the following command: ``` scp -vvv -p 2222 wd/day10/int_mod.ko root@localhost:/lib/modules/3.13.5/int_mod.ko ``` And I get Connection refused error more specifically (I forwarded 2222 to 22 of virtual machine.): ``` Executing: program /usr/bin/ssh host localhost, user root, command scp -v -p -d -t /lib/modules/3.13.5/int_mod.ko OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug2: ssh_connect: needpriv 0 debug1: Connecting to localhost [127.0.0.1] port 22. debug1: connect to address 127.0.0.1 port 22: Connection refused ssh: connect to host localhost port 22: Connection refused lost connection ``` What I don't understand is I can easily connect to ssh using ``` ssh -p 2222 root@localhost ``` I can connect without any problem.

Original source