Unsuccessful with Github: permission denied (Publickey)

I am trying to understand the configuration of ssh GitHub with Ansible (I am working on Ansible: Up and Running book). I ran into two problems.

Access denied (publication) - When I first started the playbook ansible-playbook mezzanine.yml, I received permission:

failed: [web] => {"cmd": "/usr/bin/git ls-remote '' -h refs/heads/HEAD", "failed": true, "rc": 128}
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

msg: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

FATAL: all hosts have already failed -- aborting

Well, right, I see that a few people had this problem. So I jumped into application A when starting Git with SSH and said to start ssh-agent and add id_rsa public key:

eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa

Conclusion: Identity AddedI ran ssh-agent -lto check and get a long string: 2048 e3:fb:...But I got the same result. So I checked the Github docs on ssh key generation and troubleshooting, which recommended updating the ssh configuration file on my host machine:

Host github.com
    User git
    Port 22
    Hostname github.com
    IdentityFile ~/.ssh/id_rsa
    TCPKeepAlive yes
    IdentitiesOnly yes

. , rsa, .

. , Github " (publicickey)".

Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.
Permission denied (publickey).

Github .

ssh-keygen -t rsa -b 4096 -C "me@example.com"

.ssh git_rsa.pub. :

$ ssh -i ~/.ssh/git_rsa.pub -T git@github.com
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/Users/antonioalaniz1/.ssh/git_rsa.pub' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: ~/.ssh/github_rsa.pub
Permission denied (publickey).

chmod 700 , Permission denied (publickey). Github, , ssh-rsa. . ( -BEGIN PRIVATE KEY--, ); , , .

Ansible YAML:

- name: check out the repository on the host
  git: repo={{ repo_url }} dest={{ proj_path }} accept_hostkey=yes

  vars:
    repo_url: git@github.com:lorin/mezzanine-example.git

ansible.cfg ForwardAgent:

[defaults]
hostfile = hosts
remote_user = vagrant
private_key_file = .vagrant/machines/default/virtualbox/private_key
host_key_checking = False

[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o ForwardAgent=yes

Ubuntu Trusty64 Mac OS. - / Github, .

+4
3

, , , , "ssh -i". :

ssh -i ~/.ssh/git_rsa -T git@github.com

( , git_rsa, git_rsa.pub).

, , ssh-agent. :

ssh-add ~/.ssh/git_rsa

:

ssh-add -l

, Ansible , :

ansible web -a "ssh-add -l"

, , GitHub ssh, :

ansible web -a "ssh -T git@github.com"

- :

web | FAILED | rc=1 >>
Hi lorin! You've successfully authenticated, but GitHub does not provide shell access.
+1

, , .

URL.

:

repo_url: git://github.com/lorin/mezzanine-example.git
+1

, ( ).

, ssh , ( ... , , , , , , ). , ansible test , , .

ansible -vvv all -a "ssh -T git@github.com"

, , ( ), - ssh .

Github ssh docs

, , ssh'd , . , , .

[paramiko_connection]
record_host_keys = False

,  host_key_checking = False

-o StrictHostKeyChecking=no

ssh ,

-o UserKnownHostsFile=/dev/null

ssh args,

: 9442

, , .

,

0

Source: https://habr.com/ru/post/1615457/


All Articles