I've recently installed CentOS 6 on an old Dell PC. I'm trying to setup OpenSSH at the moment, I been following some tutorials (http://www.youtube.com/watch?v=QKafb0koJEg) on You Tube, while they have been very helpful I'm at the point where I need to ask some questions.

My goal here is to be able to access the server from my work computer and from my personal laptop (which will be on the same home network as the server).

I've installed OpenSSH with no issues.

The first thing I was advised to do was change the default port.

So in the sshd_config file, I've changed Port 22 to Port xxxx (where xxxx is a obviously a four digit value).

I then restart the sshd service. I've also configured my router for forward port 22 onto xxxx.

Is there anything else I need to do?

I've generated the keys on my laptop, and I'm trying to copy them to the server as follows:

scp id_rsa.pub xxxxxxxx@localhost:.ssh/authorized_keys

but this command fails with the following error message:

ssh: connect to host localhost port 22: Connection refused lost connection

Any help appreciated.


  • 1. changing the port sshd is listening is not port forwarding, 2. trying to connect to the port you just changed fails for obvious reasons, 3. why do you use some random youtube video instead of the proper documentation? – dawud Jun 27 '13 at 20:30
  • You can't ssh into localhost port 22 if you changed the port to xxxx. Why don't you simply change it back to port 22 and let your router forward port 22 to port 22 on your openssh server? – TheCleaner Jun 27 '13 at 20:56
  • @dawud 1) Fair point, I may not have explained that correctly, but I did mention that I performed the port forwarding on my router. 2) Would you mind explaining the obvious reasons, because its not obvious to me. 3) The random you tube video was more helpful than then documentation, that's why. – Stephen Jul 2 '13 at 19:38
  • @TheCleaner Thanks, I'm not sure why its still pointing to port 22 after I made the changes mentioned. – Stephen Jul 2 '13 at 19:46
  • His changed port is his least worry. The keys are on his laptop, he wants to copy the file to the server. He is trying to copy the files to his laptop (localhost), which is probably not running an sshd anyway. – Squeezy Jul 2 '13 at 19:56

In your current example you are using both the wrong host and port.

Please replace localhost with your server, and set the port as configured in your sshd_config like so:

scp -P XXXX id_rsa.pub username@<SERVER>:.ssh/authorized_keys

Also be aware that by forwarding port 22 from your router to your reconfigured port, you are essentially exposing port 22 to the outside. This was to be avoided through setting an arbitrary port in the beginning. Setting your router to forward another port to the sshd port on your server would probably be what you want.

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.