Cannot ssh to ubuntu vm (not localhost)
I’m trying to connect to my VM that’s running Ubuntu. I figured out its IP address as well as the IP address of my host computer and inputted into the network settings via the VirtualBox Manager like so:
Here the Host IP is the IP of my computer running the VM and the Guest IP is the IP of the VM (found using ip a command). The ports 22 are default for ssh so I left them as is.
I have installed openssh-server and it shows its active and running based on the command:
sudo systemctl status ssh
In addition, I have also run the following commands:
sudo sysctl net.ipv4.ip_forward=1
to enable port forwarding and:
iptables -t nat -A PREROUTING -p tcp -d [PUBLIC_IP] --dport 22 -j DNAT --to-destination 10.0.2.15:22 iptables -t nat -A POSTROUTING ! -s [PUBLIC_IP] -j MASQUERADE
which I found from another post.
I’ve done all I could find and think of, but for some reason when I run the following commands (neither work) from my laptop to connect to the VM:
ssh matt@[PUBLIC_IP] ssh -p 22 matt@[PUBLIC_IP] ssh firstname.lastname@example.org
I always get the same error:
ssh: connect to host [PUBLIC_IP] port 22: Connection timed out
I’ve rebooted both computers, not working. I’m completely new to Linux and I’d like to ssh to my home server in class to access notes and continue playing around and learning.
Any help would be great!
Here is the output of the command: ‘ssh matt@[HOST_PUBLIC_IP] -VV’:
The basic means to connect via ssh to another node (server) requires you have a private created on the remote node. In your case you haven’t passed that key to the
The steps to connect to a remote machine would be:
Create a public and private on the remote node (server/machine) using the tool
Download the private key to the other node (server/machine)
Make the key owner readonly via the command:
chmod 400 <path/to/private_key>
Use the private key in your
ssh -i <path/to/private_key> <username>@<remote_node_ip_address>