14

I am running Ubuntu 10.04.2 LTS. Why I can't I cd into the /var/www directory?

david@ubuntu:/var$ pwd
/var

david@ubuntu:/var$ ls -l
drwxrwxr-- 13 root root  4096 2011-02-26 21:53 www

david@ubuntu:/var$ cd www
-bash: cd: www: Permission denied

david@ubuntu:/var$ sudo cd www
sudo: cd: command not found
  • 2
    cd is a shell built-in so sudo can't be used. – Paused until further notice. Mar 4 '11 at 14:57
  • And even if it could be used, it would be pointless. There is generally no way to make another process change its working directory, so whatever the cd executable could do, it couldn't change the shell process' cwd. – David Schwartz Aug 20 '11 at 21:12
13

You need execute permission to cd into a directory.

sudo chmod o+x /var/www
  • 3
    A little bit of clarification: In the example above both root (the user) and root (the group) have the execute bit set. So members of the group root can cd into www. User david cannot cd because he is not included in the root group members. You can inspect that by viewing the contents of /etc/group – adamo Mar 4 '11 at 13:39
1

There is some reason for prohibiting the ''others'' from entering the directory, no? So I would suggest to get root access to enter that directory, do some stuff, and leave it, dropping the sudo shell.

sudo -i 
cd /var/www
# do your thing
cd -
exit
1

Just a little further info, it would be wise to create a web user and group for your system and not have services running as root. Then you can also add users to that group if needed and not be giving root privileges out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.