By kwarner04
Is it possible to create a host entry on my Ubuntu VPS to reference another droplet but using the private IP address?
Here’s what I’ve got:
I’ve blocked all the connections on mysql1 so that only web1 can access it via SSH (port 22) and mysql (port 3306).
I’d like to create a host entry so that when I’m on web1, I can just type “ssh username@mysql1” and not have to remember the private IP address.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Yes, just edit the /etc/hosts file and add them.
You would add the IP of the Droplet and then a name separated by a whitespace:
10.0.1.45 web1
10.0.1.46 mysql1
And the you can easily do what you need:
- ssh username@mysql1
But maybe you’d prefer to configure a SSH config file instead?
For example, you could edit your ~/.ssh/config on the specific Droplet and add them individually:
Host web1
HostName 10.0.1.45
Port 22
User username
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
Host mysql1
HostName 10.0.1.46
Port 22
User username
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
That way you can just do:
- ssh web1
And the SSH configuration will automatically connect with the right credentials as configured.
If you use the same SSH key for every Droplet, you don’t have to add your SSH key to the Droplet, but can add it to your local machines SSH config and remove the IdentityFile ~/.ssh/id_rsa line from your Droplets SSH configuration. To your local SSH configuration you could do:
Host mydroplet
HostName public-ip-of-your-droplet
Port 22
User username
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
ForwardAgent yes
Notice the ForwardAgent yes which means that your SSH key will be forwarded in your SSH connection. Just remember to add it to your SSH Agent (pagent for Putty, ssh-add for others) or the forwarding won’t work.
This comment has been deleted
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.