SSH resolves Permission denied (publickey).

1. Find the problem

I encountered a permission denied (publickey) error when I used ssh to remotely connect to the server in the local windows. From the csdn blog: Solve Permission denied (publickey). I was inspired.

2. Analyze the problem 

In the above blog, the permission error of the server public key folder is mentioned, and the following command can be used to change it: 

// 更改文件所有权。
# chown -R your_user:your_group ~/.ssh  

Inspired by your_group inside, I can't help but wonder what is the difference between my group and the other two accounts on the server (these two accounts can normally use ssh to remotely connect to the server), so I use the command id username to check and compare my The difference between the group of the account and their two accounts. The result is as follows:

 

 I was surprised to find that my gid and groups are not the same as theirs!

What are gid and groups : In the Linux system, each user can belong to multiple groups at the same time, for example, the other two accounts belong to xy213 and docker, and each file and directory can also belong to multiple groups. When a user accesses a file or directory, the system will check whether all the groups to which the user belongs have access rights to the file or directory. If any of the groups has access rights, the user can access the file or directory. gidis the GID of the primary group the user belongs to, andgroupsis the GID of all additional groups the user belongs to. In general, group (group) is a user rights management mechanism of linux.

3. Solve problems

So the problem is that my account lisenyu is not in their group, so I don't have server public key folder permissions. Then I used the following command to modify the group to which my account lisenyu belongs, and modified the permissions of .ssh and authoriz_keys in the home directory of my account lisenyu: 

3.1 modify group 

 

 3.2 Modify .ssh and authoriz_keys file permissions

 The function of the following command : Change the owner of the /home/lisenyu/.ssh directory and all files and subdirectories inside it to lisenyu user, and change all groups to xy213 group.

 

The function of the following command : modify the readable, writable and executable permissions of the file. 

 

 Finally problem solved.

Guess you like

Origin blog.csdn.net/weixin_45338109/article/details/130639759