Let’s assume that you’re asked to create an HDFS user home directory for a user named “goldberg“.
First of all, verify that the user is exists in the server.
If you’re creating the user directory for goldberg and set the ownership as goldberg:goldberg with restricted permissions, then none can access the dir except user ‘goldberg’. If the user is not present in the server, then this serves no purpose.
So, first create the user account in the server if the user doesn’t exists.
To verify user exist in the server:
# cat /etc/passwd | grep goldberg --> This will show if the user is present in the server. If present, it will return output in below form. goldberg:x:1000:1000:/home/goldberg:/bin/bash # id goldberg --> If present, this will return the user id, group information of user.
To create a local user account in the server:
#useradd goldberg #passwd goldberg --> To set a password for this user account
The below command will create a directory in the HDFS with given name.
# hdfs dfs -mkdir /user/goldberg
If the directory has to be created by the hdfs user,
# sudo -u hdfs hdfs dfs -mkdir /user/goldberg
To change the ownership of the directory to goldberg.
#sudo -u hdfs hdfs dfs -chown goldberg:goldberg /user/goldberg