8

I can successfully connect to my server via ssh but when trying to run the scp command I get a connection time out.

$ scp ~/.ssh/id_rsa.pub [email protected]:id_rsa.pub
ssh: connect to host 192.168.12.2 port 22: Connection timed out
lost connection

Yes I do have openssh-client and openssh-server installed on both my machines the client and the server.

My router is also configured to forward ssh port 22 and no I don't have a firewall enabled.

Kevin
  • 40,087
  • 16
  • 88
  • 112
user3802988
  • 81
  • 1
  • 1
  • 3
  • Do you use any special arguments to ssh to the server? In particular, `-p`? – derobert Jul 03 '14 at 19:02
  • No it ssh directly without any arguments, My setup is passwordless with ssh key authentication. – user3802988 Jul 03 '14 at 19:05
  • So, to be clear, if you run `ssh [email protected]` from the same terminal, immediately before or after the scp attempt, it works? – derobert Jul 03 '14 at 19:17
  • Yes I can ssh no problem but scp keeps timing out. – user3802988 Jul 03 '14 at 19:19
  • 1
    That's very weird. Because `scp` works by running `ssh`. While its sitting there (before the timeout) you should be able to catch the `ssh` command via `ps x | grep scp` or similar. Does that command work if you run it directly, minus the `scp -t .` at the end? – derobert Jul 03 '14 at 19:25
  • When I run `ps x | grep scp` I get `8598 pts/0 S+ 0:00 grep --colour=auto scp` – user3802988 Jul 03 '14 at 19:29
  • You need to run that while you're running that scp command (between when you hit enter and when it says connection timed out). That presumes you're running ps as the same user; you can use `ps ax` if its as a different user. – derobert Jul 03 '14 at 19:32
  • Okay not I got this `8786 pts/1 S+ 0:00 scp /home/victorvaldezhidalgo1/.ssh/id_rsa.pub [email protected]:id_rsa.pub 8787 pts/1 S+ 0:00 /usr/bin/ssh -x -oForwardAgent=no -oPermitLocalCommand=no -oClearAllForwardings=yes -l root -- 192.168.12.2 scp -t id_rsa.pub 8790 pts/0 S+ 0:00 grep --colour=auto scp` – user3802988 Jul 03 '14 at 19:35
  • scp works on the server side but not on the client side. – user3802988 Jul 03 '14 at 19:38
  • 1
    I'm confused by your comment that it works on the server side but not the client side? I thought we were only trying from one side??? Does `ssh` (client) work from the side you're running `scp` on? – derobert Jul 03 '14 at 20:14
  • 2
    1. try scp -i with a path to your keys 2. try -v to get more info on the time out – denten Jul 03 '14 at 20:15
  • yes @derobert it works on my side scp doesn't it time out – user3802988 Jul 03 '14 at 20:18
  • does `/usr/bin/ssh -x -oForwardAgent=no -oPermitLocalCommand=no -oClearAllForwardings=yes -l root -- 192.168.12.2` work? That's the command scp is running (without the scp part). – derobert Jul 03 '14 at 20:19
  • 1
    I go it working again, but with a different authentication key, the previous one had a password for encryption reasons and then well I took it off. – user3802988 Jul 03 '14 at 21:36
  • When you say that SSH works, do you mean an interactive session? If you run a command that produces a lot of output, like `ssh yes | head -n 99999 >99999.out`, does it work? This could be an [MTU problem](http://unix.stackexchange.com/questions/4261/cant-access-select-https-sites-on-linux-over-pppoe/4319#4319). – Gilles 'SO- stop being evil' Jul 03 '14 at 23:44
  • How does the route between the client and the server look like? Post the output of `traceroute -n 192.168.12.2`. This could be a grumpy firewall somewhere in between. – Gilles 'SO- stop being evil' Jul 03 '14 at 23:46
  • 1
    Is this solved? It is a bit hard to tell from your last comment. I think that derobert's suggestion is a good one. From the `ssh_config` `man` page: `ClearAllForwardings - Specifies that all local, remote, and dynamic port forwardings specified in the configuration files or on the command line be cleared. This option is primarily useful when used from the ssh command line to clear port forwardings set in configuration files and is automatically set by scp(1) and sftp(1). The argument must be yes or no. The default is no.` – Warwick Jul 04 '14 at 00:36

2 Answers2

0

I am a little confused by your command because I don't understand where you are trying to drop the file but if you fix this, it should work:

This is wrong:

scp ~/.ssh/id_rsa.pub [email protected]**:id_rsa.pub**

The above line does not have the correct path. It should look like this:

scp ~/.ssh/id_rsa.pub [email protected]:/root(or other user path)/.ssh/id_rsa.pub

Basically what you are missing is the ' / ' after the ' : ' and the correct path location to where you want to drop the file. Also as a side-note, you just need the path, the name of the file at the end of that path works more like a renaming feature. So using the above example again, this too is also valid:

scp ~/.ssh/id_rsa.pub [email protected]:/root(or other user path)/.ssh/
devnull
  • 5,331
  • 21
  • 36
0

Make sure you aren't using the wrong port. To specify a port, pass the -P option. See also https://askubuntu.com/a/182482

s2t2
  • 101
  • 1