I am on a CentOS guest OS on a VirtualBox. I need to connect to this server through SSH using its public IP. More importantly, I need to connect to this server from within the guest host.

I have tried port forwarding with NAT as some forum suggested but I think I am lost there.

SSH output is just

root@localhost ~]# ssh user@xx.xxx.xxx.xxx
ssh: connect to host xx.xxx.xxx.xxx port 22: Connection refused

I am able to connect to the server through host machine.

  • Is your VM (CentOS) has a private ip or public one? – Wissam Roujoulah Dec 20 '16 at 7:33
  • Is you hosting server run linux ? – Wissam Roujoulah Dec 20 '16 at 7:40
  • @WissamAl-Roujoulah The server I am trying to connect from my Centos guest OS has both public and private ip. The server I am trying to connect is Red Hat Enterprise 7 – Shashank Vyas Dec 21 '16 at 6:06
  • can you access the internet from your centos ? – Wissam Roujoulah Dec 21 '16 at 6:38
  • @WissamAl-Roujoulah yes – Shashank Vyas Dec 21 '16 at 6:42

Make sure to forward your ports on your target machine. (Ensure that port 22 is open in your router) After this you may need to ensure that your ssh service is running on your target machine. Run this: "service ssh start" without quotes; or you can run "service --status-all | grep ssh" to check if it is already running.

After these are taken care of, if you are wanting to ssh into a root account you may need to edit the ssh config file.


That link is for Kali but check step 4 where it says permit root login. Follow that step to enable ssh into root account.

Permit Root Login

Once these are setup you shouldn't have any issues using ssh.

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.