"Cannot change directory to/home/XXX: Permission denied"

Source: Internet
Author: User
Tags mysql manual

System: centos5.x

Previously, when I installed MySQL, the command for creating a user was as follows:

Shell> groupadd MySQL
Shell> useradd-G MySQL
Shell> Cd/usr/local

 

When you view/etc/passwd, the record is as follows:

MySQL: X: 501: 502:/home/MySQL:/bin/bash

From the above records, we can see that MySQL is a common user (UID 500 + ).

 

Check the Home Directory of MySQL:

Drwx ------ 2 MySQL 4096 Apr 15 MySQL

 

Well, there is no problem switching from the root user to MySQL. So I have never encountered any problems in this step. Next, let me talk about the problems encountered in this step.

If you carefully observe MySQL Manual (2.2. Installing MySQL from generic binaries on Unix/Linux), you will find that its operation command is as follows:

Shell> groupadd MySQL
Shell> useradd-r-g MySQL
Shell> Cd/usr/local

 

Its useradd adds an option '-R', which means "Create System Account ". The UID of MySQL in/etc/passwd can reflect this point:

MySQL: X: 101: 502:/home/MySQL:/bin/bash

 

After the user is created, the root switch to MySQL operation may occur unexpectedly:

# Su-MySQL
Su: Warning: cannot change directory to/home/MySQL: insufficient Permissions
-Bash:/home/MySQL/. bash_profile: insufficient Permissions
-Bash-3.2 $

 

In my opinion, "Permission denied" is not displayed in the root switch operation under normal circumstances. Why? By querying some information on the Internet, there is a saying that the user's permissions have encountered problems. For more information, see here. But this is not the reason. Through observation, the problem is shown here:

Drwx ------ 2 504 MySQL 4096 APR 29 MySQL

The problem of incorrect owner identity is well solved:

# Chown-r MySQL/

 

Cause analysis: the cause of the above primary identity problem is actually very simple, that is, when a new MySQL user (system UID) is created, it uses the Home Directory of a common MySQL user (using userdel to delete an old account with the same name without the '-R' option to keep its home directory. In this case, when the UID is inconsistent (the main identifier of the home directory is not updated by the system), and the user of this uid does not exist in the system, therefore, "Permission denied" occurs when the root user switches to the user ".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.