Hadoop home directory access issue- mkdir: Permission denied: user=vagrant, access=WRITE, inode=”/user/vagrant”:hdfs:hdfs:drwxr-xr-x

When you install hadoop for the first time on your sandbox/virtual machine you might face some access issues. Here, I had created a 3 node cluster in my laptop using vagrant and virtaulbox.

Firts, I connected to node1 using ssh

>> vagrant ssh node1

>> pwd
/home/vagrant

>>hadoop version

Hadoop 2.7.1.2.3.6.0-3796
Subversion git@github.com:hortonworks/hadoop.git -r d712e2d662051975eea2dc014c1d07a8f0ac8057
Compiled by jenkins on 2016-06-23T15:40Z
Compiled with protoc 2.5.0
From source with checksum dd27ba8f8a26d4f721313528724faf
This command was run using /usr/hdp/2.3.6.0-3796/hadoop/hadoop-common-2.7.1.2.3.6.0-3796.jar

Now I want to check the contents of my home directory in hdfs

>>hadoop fs -ls
ls: `.’: No such file or directory

I initially thought it was because I dont have a /user/vagrant directory present in hdfs (This is the default directory for user vagrant)

>>hadoop fs -mkdir -p /user/vagrant
mkdir: Permission denied: user=vagrant, access=WRITE, inode=”/user/vagrant”:hdfs:hdfs:drwxr-xr-x

This is because the /user/vagrant is owned by hdfs and we have to run the command as superuser hdfs,

>>sudo -u hdfs hadoop fs -mkdir -p /user/vagrant
>>sudo -u hdfs hadoop fs -chown vagrant /user/vagrant

Now you can see the ownership of /user/vagrant changed

>>hadoop fs -ls /user
Found 2 items
drwxrwx— – ambari-qa hdfs 0 2016-07-05 05:34 /user/ambari-qa
drwxr-xr-x – vagrant hdfs 0 2016-07-14 03:44 /user/vagrant

Lets create couple of files in the vagrant user directory

>>hadoop fs -touchz ./my_data.txt
>>hadoop fs -touchz ./my_data2.txt

Now, we can list the files in vagrant user directory

>>hadoop fs -ls .
Found 2 items
-rw-r–r– 3 vagrant hdfs 0 2016-07-14 04:27 my_data.txt
-rw-r–r– 3 vagrant hdfs 0 2016-07-14 04:27 my_data2.txt

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s