Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chmod unable to change permissions

I'm facing an annoying problem. It's been pretty frustrating. I am using a computer at my school to work on the Coursera Startup class. I am trying to connect to an Amazon EC2 instance. I downloaded the key pair. I check permissions.

mac5-library:startup roh21$ ls -l
total 6
-rw-rw-rw-@ 1 roh21  108  1692 Jun 22 16:45 startup-class-key.pem

So, it's not secure. So I need to change the permissions. I try:

mac5-library:startup roh21$ chmod 400 startup-class-key.pem
mac5-library:startup roh21$ ls -l
total 6
-r--r--r--@ 1 roh21  108  1692 Jun 22 16:45 startup-class-key.pem

Still has read permissions to everyone. Just to demonstrate what happens I do this:

mac5-library:startup roh21$ chmod 600 startup-class-key.pem
mac5-library:startup roh21$ ls -l
total 6
-rw-rw-rw-@ 1 roh21  108  1692 Jun 22 16:45 startup-class-key.pem

Is it impossible to change permissions to the user without root permission? I'd be grateful for any kind of help.

like image 739
Rohit Avatar asked Jun 22 '13 21:06

Rohit


People also ask

Why is chmod not changing permissions?

You got this error because your user is not the owner of /root folder. So you can't change the permission of your folder other than the root user. You need to switch to your root account and run the commands as shown below.

How do I force chmod to change permissions?

To change directory permissions in Linux, use the following commands: chmod +rwx filename to add permissions; chmod -rwx directoryname to remove permissions; chmod +x filename to allow executable permissions; and chmod -wx filename to take out write and executable permissions.

What to do if chmod is not working?

Use the dynamic linker/loader to run chmod Another clever trick is to run chmod (yes, even without it having execute permission) by supplying it as an argument to the dynamic linker/loader. This is similar to running a script that doesn't have execute permission set by supplying it as an argument to bash.

What does chmod 644 mean?

Permissions of 644 mean that the owner of the file has read and write access, while the group members and other users on the system only have read access.


1 Answers

Probably not related to initial questions problem, but can be useful. (especially to Unix novices like myself)

Chmod will not work if you are not an owner of resources.

You should run chown first:

$ sudo chown -R $(whoami) .

and then

$ sudo chmod -R +rwX .

First command will change owner of everything in current folder to be logged in user, and second give them read write execute permissions. Just for example, you, probably, should not change ownership and permissions so boldly.

like image 179
yurin Avatar answered Oct 01 '22 19:10

yurin