-4

I am trying to copy a file from my computer to my server through scp command. I have changed the default sshd port from 22 to 36871. Now, the problem is when I issue the scp command over port 36871, I get a "Connection refused" error, as it tries to connect through the default port 22. I issue the command as follow:

sudo scp /Users/developer/Desktop/file.zip -P 36871 [email protected]:public_html

I don't have this problem when I change the port back to 22 and issue the following command:

sudo scp /Users/developer/Desktop/file.zip -P 22 [email protected]:public_html

Update: It seems it does not have to do with my server's firewall settings. The problem is that when I issue the command with a port other than 22, my computer's firewall (Little Snitch) shows that the terminal wants to connect with port 22. In other words, the terminal does not even try the other port. I think there is a problem with the command itself. Do I need to enter the port in some other arrangement?

Any ideas would be appreciated.

Thanks

8
  • Possible duplicate of What causes the 'Connection Refused' message?
    – user9517
    Apr 5, 2016 at 17:03
  • @lain Please read my update. The above link did not help. I am here for help.
    – developer
    Apr 5, 2016 at 17:34
  • Disdainful bigotry is all I got from you. Shame! Look at the answer I provided myself and at least learn how to read a question! Putting on a question as off-topic, I have oftentimes encountered in serverfault, is another way of evading the shame of not being able to answer a question.
    – developer
    Apr 8, 2016 at 10:11
  • Actually I v-t-c as a dupe which it is. Because you were not correctly specifying the port, scp defaulted to 22. As you have nothing listening on 22 then you get the Connection Refused message. If you have read the duplicate carefully you would have learned that but hey ho lead a horse to water and all that.
    – user9517
    Apr 8, 2016 at 13:07
  • @lain. And you preferred, all condescendingly, to direct me to a post where I MAY have found the answer, rather than dropping a simple comment as "specify your port right after scp". As simple as that! And if you really wanted to help! You know, people like you tend to make life a lot more troubling than it can sometimes actually be! The good thing about such forums or websites is that you do not need to read a whole book entirely before you get the clue or the right answer to a minor problem.
    – developer
    Apr 10, 2016 at 8:50

2 Answers 2

2

Ok, I think I found the answer after some experimentation. I only needed to enter the remote port after scp. So here is the right command:

sudo scp -P 36871 /Users/developer/Desktop/file.zip [email protected]:public_html
0

You probably have a port specifically configured in /etc/ssh/ssh_config. Port=XXX in the config somehow overrides -oPort=XX so I assume -P too (at least on this one machine I was using). It's actually super annoying. If its not that, check for a file called config or .config or something like that in your ~/.ssh/config file.

[Edit: Fixed file name.]

6
  • Yes, I have specified port 36871 as the default port instead of port 22 in /etc/ssh/sshd_config.
    – developer
    Apr 5, 2016 at 16:58
  • If the below correction doesn't work, can you doublecheck the firewall rules? Try using netcat: nc -v -v -w 5 XXX.XXX.XXX.XXX 36871 That should print out if the port is open to the world. Apr 5, 2016 at 17:00
  • Sorry I mean ssh_config! Apr 5, 2016 at 17:00
  • ssh_config is specificaly for clients Apr 5, 2016 at 17:01
  • No, I have not changed the port number in /etc/ssh/sshd_config. Do I have to?
    – developer
    Apr 5, 2016 at 17:21

Not the answer you're looking for? Browse other questions tagged .