190

When cding into one of my directories called openfire the following error is returned:

bash: cd: openfire: Permission denied

Is there any way around this?

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
user812954
  • 3,951
  • 3
  • 19
  • 18

8 Answers8

230

@user812954's answer was quite helpful, except I had to do this this in two steps:

sudo su
cd directory

Then, to exit out of "super user" mode, just type exit.

Jonathan
  • 18,229
  • 10
  • 57
  • 56
192

Enter super user mode, and cd into the directory that you are not permissioned to go into. Sudo requires administrator password.

sudo su
cd directory
Chillar Anand
  • 27,936
  • 9
  • 119
  • 136
user812954
  • 3,951
  • 3
  • 19
  • 18
76

If it is a directory you own, grant yourself access to it:

chmod u+rx,go-w openfire

That grants you permission to use the directory and the files in it (x) and to list the files that are in it (r); it also denies group and others write permission on the directory, which is usually correct (though sometimes you may want to allow group to create files in your directory - but consider using the sticky bit on the directory if you do).

If it is someone else's directory, you'll probably need some help from the owner to change the permissions so that you can access it (or you'll need help from root to change the permissions for you).

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • Been googling for an hour now trying to fix the fact that I could not SSH without using "sudo" (which I knew had to be wrong) - and this fixed it. Finally! – GrayedFox Nov 02 '18 at 16:10
  • Would it be possible to give read-only permission to it? When I do `chmod 0444 ` I start to have same error message – alper Dec 01 '21 at 13:16
  • If the directory permissions are 444, then you can read the directory to find which files are named in it, but you cannot access those files, regardless of the permissions on the files. – Jonathan Leffler Dec 01 '21 at 13:38
35

chmod +x openfire worked for me. It adds execution permission to the openfire folder.

wcyn
  • 3,826
  • 2
  • 31
  • 25
25

Alternatively, you can do:

sudo -s
cd directory
10

You've got several options:

  • Use a different user account, one with execute permissions on that directory.
  • Change the permissions on the directory to allow your user account execute permissions.
    • Either use chmod(1) to change the permissions or
    • Use the setfacl(1) command to add an access control list entry for your user account. (This also requires mounting the filesystem with the acl option; see mount(8) and fstab(5) for details on the mount parameter.)

It's impossible to suggest the correct approach without knowing more about the problem; why are the directory permissions set the way they are? Why do you need access to that directory?

sarnold
  • 102,305
  • 22
  • 181
  • 238
4

I know this post is old, but what i had to do in the case of the above answers on Linux machine was:

sudo chmod +x directory

Sebastian
  • 402
  • 3
  • 12
2

Unless you have sudo permissions to change it or its in your own usergroup/account you will not be able to get into it.

Check out man chmod in the terminal for more information about changing permissions of a directory.

Gerard Roche
  • 6,162
  • 4
  • 43
  • 69
John Riselvato
  • 12,854
  • 5
  • 62
  • 89