使用HDFS put命令上传patternsToSkip文件时遇权限拒绝错误求助
Let's break down your issue and fix it step by step:
First, let's understand the core problem from the error message:
Permission denied: user=root, access=WRITE, inode="/user":hdfs:hdfs:drwxr-xr-x
This tells us that the HDFS /user directory only grants write permissions to its owner (the hdfs user). All other users—including root and biadmin—only have read and execute permissions here. Directly uploading files to the /user root directory violates HDFS's security model, which is why your attempts are failing across different users.
Recommended Fix (Follows HDFS Best Practices)
You should use a dedicated user home directory in HDFS instead of writing directly to /user:
- Switch to the
hdfsuser (the only account with permissions to create directories under/user):su - hdfs - Create a home directory for your target user (e.g.,
biadmin):hdfs dfs -mkdir /user/biadmin - Assign ownership and proper permissions to let
biadmincontrol the directory:hdfs dfs -chown biadmin:biadmin /user/biadmin hdfs dfs -chmod 755 /user/biadmin - Exit the
hdfsuser session, switch tobiadmin, and upload your file to the new directory:exit su - biadmin hdfs dfs -put patternsToSkip /user/biadmin/
Temporary Workaround (Not Recommended for Production)
If you need a quick test upload and don't mind the security risk, you can temporarily grant write access to all users on /user (remember to revert this afterward):
su - hdfs hdfs dfs -chmod o+w /user # Upload your file here hdfs dfs -put patternsToSkip /user/ # Revert permissions immediately hdfs dfs -chmod o-w /user
Note on Your Failed hdfs User Attempt
When you tried using the hdfs user, you might have had a path mismatch or weren't in the correct working directory. The hdfs user can write directly to /user, but it's still better practice to use /user/hdfs/ for its own files. Double-check that your local patternsToSkip file exists in your current working directory, or use an absolute path to specify it (e.g., hdfs dfs -put /path/to/patternsToSkip /user/hdfs/).
内容的提问来源于stack exchange,提问作者Sea Star

