I’m working on a Virtual Machine where I have Ubuntu Server, in that server I connect to my Droplet (Ubuntu as well), via ssh , but when I tried to login with this syntax:


ssh subdomain.mydomain.com 

It brings this error :

Permission denied (publickey)

But If I use any of this syntax:

ssh my_user@subdomain.mydomain.com
ssh my_user@Droplet_IP

I login without a problem. So I was just wondering If the first syntax is wrong or I have something messed up within sshd_config file or my Droplet firewall service configuration (just my IP can access to my droplet).

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
2 answers

The short answer is… you can configure the ssh client with a simple text file located here:

~/.ssh/config

(~ is a shortcut to your Ubuntu VM user’s home directory)

Inside that file these lines would provide the behavior you want:

Host subdomain.mydomain.com
    User my_user

Just as an aside, the /etc/ssh/sshd_config manages the SSH service running on an ubuntu server, not the ssh client you use to connect to one. /etc/ssh/ssh_config (no d in the filename) does allow you set global options for the ssh client to use but more typical in these cases is the per-user config mentioned above.

Hello, @k0r3n

If you use the ssh command without specifying the user a session will be created with the user that is currently in use on your Virtual Machine. This is the reason this works fine when you specify the username.

You can follow up the example above which or simply create an alias in your .bashrc profile for quick access.

You can open the file with any text editor:

sudo nano ~/.bashrc

and add the following line:

alias dropletssh='ssh my_user@Droplet_IP'

Save the file and exit. Then simply reload the .bashrc profile with this command:

source ~/.bashrc

Now if your type dropletssh in the command line (terminal) you will connect to your droplet.

Hope that this helps!
Regards,
Alex