permission denied publickey
The "Permission denied (publickey)" error typically occurs when you try to access a server using Secure Shell (SSH) and the authentication process fails. Here are several potential reasons why this might happen, and steps you can take to resolve the issue:
1 SSH Key Not in Authorized Keys: Ensure that your public SSH key is added to the authorized_keys
file on the server you're trying to access.
** SSH Key Being Used**: If you have multiple SSH keys, your client might be using the wrong one. You can specify the key with ssh -i /path/to
.
Improper File Permissions: The SSH keys and the authorized_keys
file must have strict file permissions set, or else the SSH service will reject them for security reasons.
Check SSH Configurations: Sometimes the error can be on account of specific SSH configurations. Check the SSH configuration file (/etc/ssh/sshd_config
the server) for allowed key types and options like PasswordAuthentication
, PubkeyAuthentication
, and so forth.
Incorrect Username: If you using a username that does not exist on the server or using a correct username but with a wrong SSH key, you will face issue.
Using the Right SSH URL: When cloning from Git services like GitHub or GitLab, make sure you are using the correct SSH URL.
Server Issues: The server might be set up in a way that it does not accept the public key authentication method or your key is not compatible (for example, some services do not accept DSA keys).
If you're still having trouble, try using ssh -v
for verbose, which can provide more information about the steps where the authentication process is failing. This can give you more insight into what needs to be fixed.
google.com
docs.github.com
blog.csdn.net
i used sudo, so it try to use root as ssh user?
Yes, when you prefix ssh
with sudo
, you are essentially attempting to SSH into the remote server as the root user of your local machine, not as your regular user. The SSH client will look for the root user's SSH keys, usually located in /root/.ssh/
, instead of your current user's keys in your home directory (~/.ssh/
). If the root user on your local machine does not have the appropriate SSH keys configured to match those on the remote server, or if the remote server does not permit root logins, you will encounter the "Permission denied (publickey)" error.
To correct this, you may need to either SSH as your regular user (without using sudo
) or ensure that the root user on your local machine has the correct keys and that the server is configured to accept root logins via SSH (which is typically discouraged due to security concerns).
google.com
tecmint.com
linuxgenie.net
where is root ssh key
The location of the root SSH key on a Linux server depends on the distribution and exact configuration of the server. However, in most cases, the root SSH key is located in the following directory:
/root/.ssh/
This directory typically contains the id_rsa
(for RSA-based keys) or id_dsa
(for DSA-based keys) file, which is used for public key authentication.
If you are attempting to SSH into a remote server as the root user, you may need to specify the location of the root SSH key using the -i
or -C
option in the ssh
command. For example:
ssh -i /root/.ssh/id_rsa root@remote-server
Note that you should only use this approach if you have permission to access the remote server as the root user, and you should avoid using it in production environments due to security concerns.