Lost permission after chmod command - linux

I accidentally executed the following command:
chmod -rwxr-xr-x folder_name
And after the command, I was not able to access the folder folder_name. I'm wondering if there is any way that I could recover the full permission to the folder.

Related

How to give permissions for specific commands in linux

I am new to linux. I have a build.sh file which consists of a lot of mkdir commands and some rm commands. But as I have installed this new in my VB, each time I run the .sh file, it says "Permission Denied for creating directory" and fails.
So is there any way that I grant directory privileges to all users.
Can anyone help me with this
Add "sudo" in the beginning of the directory creation command i.e
sudo mkdir dir_name
The issue might be with the directory in which the mkdir command is being run.
Use the command ll or ls -l to check the directory permissions.
If your directory doesn't have write privilege for the current user, you can run
chmod -R u+w /path/to/directory
This might require you to use sudo if permission is denied.
If you want to enable it for all users, run
chmod -R ugo+w /path/to/directory
Alternatively, a quick fix would be to run the build.sh file as root
sudo /path/to/build.sh
However, this approach is not advised unless you always run it as root

chmod: changing permissions of ‘my_script.sh’: Operation not permitted

when I'm trying to make shell script that error is shown ,what i must do ??
[rehamadel#localhost bin]$ sudo vi my_script.sh
[sudo] password for rehamadel:
[rehamadel#localhost bin]$ ls -l my_script.sh
-rw-r--r--. 1 root root 52 Jul 30 19:25 my_script.sh
[rehamadel#localhost bin]$ chmod u+x my_script.sh
chmod: changing permissions of ‘my_script.sh’: Operation not permitted
Resolving the operation not permitted error:
sudo chmod u+x my_script.sh
You created the file via:
sudo vi my_script.sh
# editing
This means, the owner and group of the file is root. You are not allowed to change files of it by default. You need to change permission (chmod does it) or change the owner:
sudo chown you:yourgroup my_script.sh
This should do it. Save the trouble, without creating the file via sudo.
You've created file my_script.sh with the root user as the owner (because you used sudo), which is why you're not permitted to change the permissions as yourself.
Thus, use sudo chmod u+x my_script.sh, but note that that will make the file only executable for the root user.
To make the file executable by everyone, use sudo chmod a+x my_script.sh.
I faced this error because I uploaded the files via winscp and was trying to change permission on Linux window.
I was able to change permissions via winscp.

permission denied in a folder for a user after chown and chmod

I have a directory at
/home/ec2-user/vertica1
and I'm trying to get user dbadmin all privilages in that folder.
I've done chown to dbadmin and chmod 777 on that folder but dbadmin still gets a permission denied error.
If I put sudo in front of the command(I put dbadmi in sudoers), then it works. Why can't I get it to work without sudo?
Can dbadmin traverse /home/ec2-user? Try doing chmod a+x /home/ec2-user
There could be more reasons for being denied, like a specific acl or a LSM but this is the most likely cause.
UNIX permissions on directories
The UNIX permissions rwx¹ work on directories as follows:
r: You can view the contents of the directory (the names of the files or folders inside)
w: You can create new files, delete or rename existing files.
x: You can traverse the folder.
The traverse permission means that you can access the folder children (assuming you know its name -which you can obtain if you also have read permission-).
In this case dbadmin could read and traverse / as well as /home, but /home/ec2-user probably had a mode like drwx------ 2 ec2-user in order to protect its contents. Thus, even if you had an important file readable by anyone deep inside your home folder, other users can't get into it, since they wouldn't be able to go pass /home/ec2-user (which is exactly what you wanted to do, in this case).
¹ Note that I am skipping over the more exotic ones.
what is the result of ls -la for this dir and also parent dir? Maybe the directory doesn't have read permissions for your user.
sudo chmod ug+r vertica1
Also ec2-user directory should be writable by the user dbadmin.

mkdir: cannot create directory `pgsql': Permission denied

I want to create directory like below:
ajs#ajs-HP-Compaq-dc5800-Small-Form-Factor:/usr/local$ mkdir pgsql
mkdir: cannot create directory `pgsql': Permission denied
But I am getting error:
Permission denied
How can I resolve and create directory pgsql in this location /usr/local$
Kindly suggest me, hope for reply.
Thanks
You have to check your user name to have permission for creating directory in the folder /usr/local$
Check your permission for the folder by the command
ls -ltr /usr
Link to refer about file permissions.
You are getting a Permission denied error because you do not have access rights to create a directory in /usr/local. You can determine the access rights for these directories by using the stat command. The output will look something like this.
$> stat -c '%n %A %G %U' /usr /usr/local
/usr drwxr-xr-x root root
/usr/local drwxr-xr-x root root
Now double check who you are. You can use the whoami command or the id command invoked below twice to reveal both username and group.
$> id -un; id -gn
In the stat output, root:root owns both /usr and /usr/local and only the owner may create (write) new directories based on the access rights. In order to create the directories, I'd recommend either becoming root or trying the command with sudo. If this is not possible, I'm afraid you'll have to create the directory elsewhere or contact the administrator of that machine.
You probably have to be root to do such things in /usr/local.

ant Permission Denied problem

After extracting and saving the ant files into an opt/ directory and setting the path variable
to $ANT_HOME/bin
I ran the following command on a CentOS 5
ant -version
and I am getting the following error
-bash:/path/opt/apache-ant-1.8.2/bin/ant: Permission denied
Is there some permission I am supposed to set or some typical source of this problem?
Thanks!
If you own the file, try
chmod u+x /path/opt/apache-ant-1.8.2/bin/ant
If someone else owns it, either sudo or become root then
chmod 755 /path/opt/apache-ant-1.8.2/bin/ant
You need to have execute permissions on the file; the first gives execute permissions to the owner only and is probably preferable if you own the file and are the only one that uses it. The second requires root privileges and gives execute and read permission to everyone, plus write permission to the owner.
You can view the current permissions and ownership of the file by running ls -l /path/opt/apache-ant-1.8.2/bin/ant.

Resources