0

I'm working on a Virtual Machine where I have Ubuntu Server, in that server I connect to my cloud server (ubuntu), via ssh , but when I tried to log in with this syntax:

ssh subdomain.example.com 

It brings this error :

Permission denied (publickey)

But If I use any of this syntax :

ssh my_user@subdomain.example.com
ssh my_user@cloud_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 cloud server firewall service configuration. I've used ssh -vvv subdomain.example.com to debug it and this is what It shows: image

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
k0r3n
  • 1
  • 3
  • If the answer below didn't help you, can you explain what happens when you try it? Your question shows different behaviour only when not specifying a user – grifferz Feb 08 '21 at 12:14
  • Instead of showing screenshots of terminal output, please copy and paste the output into your question, so it becomes searchable. – Andrew Schulman Feb 08 '21 at 15:34

2 Answers2

3

Your user name on the client machine is used as default for ssh connection to remote machines. You say it works when you do:

ssh user@subdomain.mydomain.com

but not when you do:

ssh subdomain.mydomain.com

Therefore we must assume that your user name locally is not user.

If that is the case you can either specify user every time or you can add an entry to your $HOME/.ssh/config file that says "my user name at subdomain.mydomain.com is user":

Host subdomain.mydomain.com
    User user

DNS does not come in to it because both of your examples are connecting to the same host. If this is not the case and you have made a copy/paste/redaction error, please update the question and consider not redacting the real host names involved as it makes it harder to help you.

grifferz
  • 948
  • 5
  • 13
0

SSH command syntax

ssh your_username@host_ip_address_or_domain_points_to_the_server_ip_address

usage: ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] [-E log_file] [-e escape_char]
[-F configfile] [-I pkcs11] [-i identity_file]
[-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]
[user@]hostname [command]

Since the SSH client reads from the known_hosts file when connecting to a different system, the current user will need to have the proper permissions on that file.

Without the proper permissions, you may see an error like this.

http://puu.sh/HeLeg/bd3b712d1e.png

If using keys to authenticate (instead of a password) you'll be locked out of the system entirely until you fix the permissions on your key files. Running these commands or recheck the permission of the below, it should remedy the problem.

$ chmod 700 ~/.ssh

$ chmod 644 ~/.ssh/authorized_keys

$ chmod 644 ~/.ssh/known_hosts

$ chmod 644 ~/.ssh/config

$ chmod 600 ~/.ssh/id_rsa

$ chmod 644 ~/.ssh/id_rsa.pub

Ryan
  • 137
  • 4