Error: Permission denied (publickey)
An error message "Permission denied" (permission denied) indicates that the server has rejected your connection. There are different reasons for this to happen. The most common examples are described below.
The command sudo
should be used with Git?
You should not use the command sudo
with Git. If you have a very good reason to use sudo
, make sure to use it with all commands (maybe it is best to use su
to get a shell as root at that point). If you generate SSH keys without sudo
and then try to use a command like sudo git push
, you won’t be using the same keys you generated.
Make sure you are connected to the correct server
We know typing is hard. Pay attention to what you type; you won’t be able to connect to "githib.com" or "guthub.com". In some cases, an enterprise network may also cause problems when solving the DNS record.
Enter the second command to confirm that you are connected to the correct domain:
$ ssh -vT [email protected]
> OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011
> debug1: Lendo dados de configuração /Users/you/.ssh/config
> debug1: Lendo dados de configuração /etc/ssh_config
> debug1: Solicitando opções para *
> debug1: Conectando a github.com [IP ADDRESS] port 22.
The connection must be made on port 22, unless you are replacing the settings to use SSH on HTTPS port.
Always use the "git user"
All connections must be made as a "git" user, including those for remote Urls. If you try to connect with your Github username, an error will occur:
$ ssh -T [email protected]
> Permissão negada (publickey).
If there is a connection failure when using a remote URL with your Github username, you can change the remote URL for the "git user".
Check your connection by typing:
$ ssh -T [email protected]
> Olá username! Você conseguiu se autenticar...
Make sure you have a key that is in use
Open the terminal.
Make sure you have a private key generated and loaded in SSH. If you are using Openssh 6.7 or earlier
# iniciar o ssh-agent em segundo plano
$ eval "$(ssh-agent -s)"
> Agent pid 59566
$ ssh-add -l
> 2048 a0:dd:42:3c:5a:9d:e4:2a:21:52:4e:78:07:6e:c8:4d /Users/you/.ssh/id_rsa (RSA)
If you are using Openssh 6.8 or later:
# iniciar o ssh-agent em segundo plano
$ eval "$(ssh-agent -s)"
> Agent pid 59566
$ ssh-add -l -E md5
> 2048 MD5:a0:dd:42:3c:5a:9d:e4:2a:21:52:4e:78:07:6e:c8:4d /Users/you/.ssh/id_rsa (RSA)
The command ssh-add
should print a long string with numbers and letters. If this does not happen, you should generate a new SSH key and associate it with Github.
Tip: In most systems, standard private keys
(~/.ssh/id_rsa
, ~/.ssh/id_dsa
and ~/.ssh/identity
) are automatically
added to the SSH authentication agent. No need to
execute ssh-add path/to/key
, unless you replace the name of
file when generating a key.
Get more details
You can also check the key being used trying to connect to [email protected]
:
$ ssh -vT [email protected]
> ...
> debug1: Arquivo de identificação /Users/you/.ssh/id_rsa type -1
> debug1: Arquivo de identificação /Users/you/.ssh/id_rsa-cert type -1
> debug1: Arquivo de identificação /Users/you/.ssh/id_dsa type -1
> debug1: Arquivo de identificação /Users/you/.ssh/id_dsa-cert type -1
> ...
> debug1: Autenticações que podem prosseguir: publickey
> debug1: Próximo método de autenticação: publickey
> debug1: Tentando chave privada: /Users/you/.ssh/id_rsa
> debug1: Tentando chave privada: /Users/you/.ssh/id_dsa
> debug1: Não há mais métodos de autenticação para tentar.
> Permissão negada (publickey).
In this example, we have no SSH key to use. " -1" at the end of the "identification file" lines indicates that SSH could not find a file to use. Further, the lines "Trying private key" also indicate that the file was not found. If there was a file, the lines would be respectively "1" and "Presenting public key":
$ ssh -vT [email protected]
> ...
> debug1: arquivo de identificação /Users/you/.ssh/id_rsa type 1
> ...
> debug1: Autenticações que podem prosseguir: publickey
> debug1: Próximo método de autenticação: publickey
> debug1: Apresentando chave pública RSA: /Users/you/.ssh/id_rsa
Check that the public key is associated with your account
Provide your public key to Github to establish a secure connection.
Open the terminal.
Start the SSH agent in the background.
$ eval "$(ssh-agent -s)"
> Agent pid 59566
- Find and write down the public key fingerprint. If you are using Openssh 6.7 or earlier:
$ ssh-add -l
> 2048 a0:dd:42:3c:5a:9d:e4:2a:21:52:4e:78:07:6e:c8:4d /Users/USERNAME/.ssh/id_rsa (RSA)
If you are using Openssh 6.8 or later:
$ ssh-add -l -E md5
> 2048 MD5:a0:dd:42:3c:5a:9d:e4:2a:21:52:4e:78:07:6e:c8:4d /Users/USERNAME/.ssh/id_rsa (RSA)
- In the upper right corner of any page, click your profile picture and click Settings.
- In the user settings sidebar, click SSH and GPG keys.
- Compare the SSH key list with the output of the command
ssh-add
.
If you can’t see your public key on Github, you’ll need to add the SSH key to Github to associate it to your computer.
Warning: if you find an SSH key that you are not using
familiar with Github, delete it immediately and contact
Support from Github or Support from Github Premium for help. A
unknown public key may indicate a possible problem of
security. For more information, see "Review the keys
SSH".
Source
https://help.github.com/pt/github/authenticating-to-github/error-permission-denied-publickey
You are sending via ssh, so you need to have generated an ssh-key previously. If you switch to https by changing the origin url to
https://github.com/Di82Rquant/repositorio-teste
it will ask for the login and password at the time of sending even without need to generate the key.– fajuchem
thanks, I did,but unfortunately the patch that github itself gave me didn’t work, when I took the patch straight from the source and put . git worked
– Di82Rquant