Setting up SSH to Ubuntu-server

I am running Ubuntu Server on a VM, but you can’t copypasta commands and stuff to it (I have set the bidirectional settings in Virtual Box – but it only works in gui-ubuntu I think). So the next best thing is just to SSH into the VM. It’s pretty much the same thing but I get to use the Terminal instead of the crappy terminal that is on the server.

But I always forget the process of setting up SSH. So here it is.

On the VM we first need to go into the settings in VirtualBox. To network and then set Bridged Adapter. This allows the VM to obtain an internal IP and connect it to the rest of the network.

sudo apt-get update
sudo apt-get install openssh-server
sudo ufw allow 22

Updating, downloading and installing openssh-server. And then we open ssh port 22 on the firewall.

Now we need to know out servers internal IP so that we can connect to it. There are a few ways to find it.

ip addr show
ip route get | awk '{print $NF; exit}'

Either way the address should look something like this:

Now let’s log in:

ssh username@

Now we get this:

Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
Please contact your system administrator.
Add correct host key in /home/user/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/user/.ssh/known_hosts:11
  remove with: ssh-keygen -f "/home/user/.ssh/known_hosts" -R
Password authentication is disabled to avoid man-in-the-middle attacks.
Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.
Permission denied (publickey,password).

Okay so that didn’t work. So let’s run the command that the error-message suggest.

ssh-keygen -f "/home/user/.ssh/known_hosts" -R

And now we can log in without any problems.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s