SSH into Ubuntu VM with VMware
I recently built a new Ubuntu VM with VMWare for my development workflow. These are the steps I used to SSH into it.
Why, you ask? Because rather than opening my VM and working directly in it, I’d rather work on my mac side with Vim via SSH. Much cleaner and easier to manage.
After downloading the latest ubuntu image, create a new vm from the iso file. You can do this under file>new>Install from disc or image.
Add the VM ip address to your computer’s host file.
Name it appropriately; The first argument is the IP address of your VM. You can get that by running ifconfig in linux. The second and third are aliases. I recommend at least one, so you can use it when you SSH rather than the IP.
xxx.xxx.xxx.xxx ubuntu test.com
Log in to your ubuntu VM, and install openssh-server
sudo apt-get install openssh-server
Create SSH key on your Ubuntu VM
This should create a public key in your .ssh folder.
ssh-keygen -t rsa
Copy public key to clipboard
There are multiple ways to do this. I use the pbcopy package.
pbcopy < ~/.ssh/id_rsa.pub
Add key to your known_hosts on your computer
The key copied to your clipboard should be added to this file.
~/.ssh/known_hosts
SSH in!
ssh ubuntuUserName@ubuntu
Bonus
Setup sshpass and you can make a simple script to ssh in easier going forward. I just called my script vm.
sshpass -p 'ubuntuPass' ssh ubuntuUserName@ubuntu
Next I plan to write a bit on my vim setup, so you can see why I prefer this way of working.
Leave a Reply