Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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
share|improve this question
2  
cd is a shell built-in so sudo can't be used. –  Dennis Williamson 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

3 Answers 3

up vote 7 down vote accepted

You need execute permission to cd into a directory.

sudo chmod o+x /var/www
share|improve this answer
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

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
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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