After successfully establishing a ssh connection between two Ubuntu systems via

ssh chh1@ from a local machine with user name chh2

I tried copying a file from my server with the following command:

scp chh1@ chh2@

chh1 is the user of the remote server. chh2 is the local user.

I get the following:

chh1@'s password: ssh: connect to host port 22: Connection refused lost connection

I ran a ping on both my server and the host and there is no connection problem. I also opened port 22 on both systems via:

firewall-cmd --zone=public --add-port=22/tcp --permanent firewall-cmd --reload

Anyone got any ideas how to solve this?

I might also add that I have no problems reading the file: cat ~/Documents/Steven/prt.csv from the machine I made the connection from.

  • Remove the chh2@ part from the destination. This is telling scp to make a remote connection to... the computer you're already on. It's not needed, and (apparently) isn't allowed. – Gordon Davisson Aug 27 at 6:19

Not enough info to help you.

First be sure that the firewall command succeded and the sshd server is running on both hosts: use "netstat -ln" on local machine to be sure that there is something listening on port 22, then use nmap on the remote machine to be sure that can see the port 22 open from the network. Repeat on both machines. This is the appropriate test to do before saying "there is no connection problem"; ping wasn't enough. I say this because looks like the remote machine (.67) is trying to connect back to the local machine (.66) and fails.

Once you are sure there is no connection problem, you must debug sshd configuration. From the output you posted, looks like you enter the password and then the connection drops. If this is the case, it's likely to be something internal to sshd. Examples:

1) crypto algos not supported one side and mandatory on the other side (check sshd versions and build flags, on both machines). 2) scp not allowed. 3) password auth not allowed. 4) password auth not allowed for specific users. 5) bidirectional auth requested and failing...

And so on. Keep going and update the question on the go. I'll do the same here with this answer.

  • Anichang, thanks for you detailed reply. I am a bit of a newby here and have found out what I did wrong. I was trying to run scp chh1@ chh2@ after establishing a ssh connection. I know now that scp actually establishes a ssh connection. That is to say you just type in the command at the terminal and that is it. In hind site this was quite a dumb question. Sorry for wasting your time. – Christian Hick Sep 11 at 23:12
  • Good to know you got your own solution. And not a waste at all: I created my account to help others; there's no real need to create an account and make questions, to find answers. Searching (without an account) brings to others having similar issues, a bit of reasoning and you're good to go without asking others. Anyway, I'm dropping stackexchange ( see arduino.meta.stackexchange.com/questions/2623/… ), I can't grant reading comments and write follow-ups. Goodbye and good luck! – Anichang Sep 12 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.