0

I'm trying to automate google cloud virtual instances remotely only using external ip addresses of virtual machines. I can ssh into the virtual machines using command line with user name shishir9159_gmail_com . But If I use any ansible commands like this:

ansible -i hosts -u shishir9159_gmail_com --private-key=~/.ssh/google_compute_engine -m ping all

and it results in this following error:

"msg": "Failed to connect to the host via ssh: shishir9159@35.202.219.6: Permission denied (publickey,gssapi-keyex,gssapi-with-mic)."

I've added some parameters in my ansible.cfg:

host_key_checking = False
ssh_args = -o ControlMaster=no

But I don't think they do much of a help according to this post:
https://serverfault.com/questions/929222/ansible-where-do-preferredauthentications-ssh-settings-come-from

And I tried many methods and recommendations. I have a service account but it doesn't seem to me necessary for this simple ping command.

noobmaster69
  • 182
  • 1
  • 3
  • 13

2 Answers2

0

The problem is in the underscores of the user name. Try to add a username without underscore or try using quote.

noobmaster69
  • 182
  • 1
  • 3
  • 13
Ahmed Abdelazim
  • 717
  • 7
  • 14
  • this user name is auto generated via Google Cloud Platform from my email address. I can ssh into vm instances via this command `ssh -i ~/.ssh/google_compute_engine shishir9159_gmail_com@35.202.219.6`. And this user name provides the authority over Virtual box Instances. Is there anyway I can rename The provided username via gcp? – noobmaster69 Dec 22 '19 at 07:58
  • This user name represents credentials attributed by GCP. This is not even about renaming cloud shell user name. With due respect, you can't change GCP credentials with just simple linux commands. – noobmaster69 Dec 22 '19 at 10:25
0

I solved the problem by adding ansible_ssh_user and ansible_ssh_pass at the hosts file. This post contain the solution. ansible SSH connection fail

noobmaster69
  • 182
  • 1
  • 3
  • 13
  • 2
    Your question and answer are confusing for me: in question you try to connect using public key, but in answer you refer to password ssh authentication. Please, update your question and/or answer to clarify. – ivan_onys Dec 25 '19 at 11:55
  • `--private-key=~/.ssh/google_compute_engine` this refers to the private key file I'm using. And public key authentication requires ssh key. – noobmaster69 Dec 28 '19 at 05:09