I have the following file xx.sh:
#!/bin/bash
echo "hi"
The permissions are defined as follows:
-rwxr-xr-x 1 root root 22 Nov 22 10:55 xx.sh*
but when I run the file ./xx.sh I get:
**-bash: ./xx.sh: Permission denied**
When running with override: bash xx.sh it runs correctly.
What is the permission issue here?
Your system is probably mounted with noexec. Verify by:
findmnt <folder>
If you have noexec in the OPTIONS, then you are not allowed to execute executable binaries in the mounted file system. You can solve using the mount command.
Related
I'm running a Ubuntu 16.04 server. On my server, I have a file in directory /home/userA/dirA:
userA#myUbuntu:~$
userA#myUbuntu:~$ pwd
/home/userA
userA#myUbuntu:~$
userA#myUbuntu:~$ ls -l
total 8
drwxrwxr-x 3 userA userA 4096 Feb 17 14:13 dirA
userA#myUbuntu:~$
userA#myUbuntu:~$ ls -l dirA/
total 7796
-rw-rw-r-- 1 userA userA 1234 Feb 17 14:05 theFile.txt
userA#myUbuntu:~$
Note the ownership here; user userA owns the file and the directory where the file resides.
I need a shell script that moves theFile.txt to another location, into a directory that is not owned by userA. Here's my script:
#!/bin/bash
echo "Attempting to move file..."
{
sudo mv /home/userA/dirA/theFile.txt /home/userB/dirB/.
} || {
echo "Failed to move file!"
}
...and the output:
userA#myUbuntu:~$ ./myScript.sh
Attempting to move file...
Failed to move file!
userA#myUbuntu:~$
As you can tell, the script runs as userA. I don't want to run it as root.
So I'm assuming the script is failing because of the permissions; a script run as userA does not have permission to move a file into a directory owned by userB. I've been trying all sorts of variations of the sudo command and others, but to no avail. I've also tried goofy workarounds, like copying the file to /tmp (that works) and then doing a chown to change file ownership (that doesn't work). But there's got to be a way to neatly do this. Any ideas?
Create a new group, add both users into it and set the appropriate permissions. After that you will be able to move files between folders.
i've been banging my head for an hour now.
Context : I decided to put my dotfiles in the repo and symlink them.
I tried to symlink and got permission denied so I decided to try a simple symlink and it just won't work.
I created a testFolder( /Users/myUserName/testFolder ) :
drwxr-xr-x 3 myUserName staff 102 24 Nov 16:47 testFolder
Inside there is a test file :
-rw-r--r-- 1 myUserName staff 53 24 Nov 16:47 test.sh
So I created a symlink to test symlinks in the parent folder with this command :
myUserName testFolder $ ln -s test.sh ../test.sh
I go to the parent folder and get this symlink :
lrwxr-xr-x 1 myUserName staff 7 24 Nov 16:52 test.sh -> test.sh
For some reasons, when I try to edit it, I get Permission denied.
If I symlink it in the same folder, I can edit it and no permission denied!
Has any body encountered this? I must be doing something wrong.
Thanx!
Symlinks with relative paths are resolved relative to the directory the symlink is in, not relative to the directory you were in when you created them. So when you run this:
ln -s test.sh ../test.sh
You’re creating a symlink that points to a file named test.sh in the same directory as the symlink, i.e. itself. What you want to do is this:
ln -s testFolder/test.sh ../test.sh
Which creates a symlink to test.sh in the testFolder sub directory under the directory the symlink is in.
Ah! Found the answer! You can't put relative links in the first argument!!
You HAVE to put absolute path in the first argument like this :
$ ln -s absolute-path-to-source ../test.sh
I have downloaded and installed Bash for Windows. When I do a simple ls -al, I get lots of permission denied errors.
I'm not clear quite how the user permissions are being resolved. Let's say that in the bash shell I set up a user called moi and has home drive /home/moi. If I then do ls -al /mnt/c, I get a bunch of permission denied errors, e.g.
ls: cannot access /mnt/c/hiberfil.sys: Permission denied
ls: cannot access /mnt/c/pagefile.sys: Permission denied
ls: cannot access /mnt/c/swapfile.sys: Permission denied total 2388
drwxrwxrwx 2 root root 0 Sep 26 18:09 .
drwxr-xr-x 2 root root 0 Jan 1 1970 ..
drwxrwxrwx 2 root root 0 Oct 22 2015 AutoDiscover
-r-xr-xr-x 1 root root 398156 Jul 26 2012 bootmgr
-r-xr-xr-x 1 root root 1 Oct 30 2015 BOOTNXT
I have checked on the "Windows side" and there is no new user called moi. So, when ls reports permission denied for /mnt/c/swapfile.sys for example, what user is being denied?
A follow on question would be: what do I need to do to get the Bash user and call it my "normal" windows user to have the same permissions?
The Windows user is the user who started bash.exe. You can verify this by creating a file from Linux in the /mnt/c directory looking at the owner of the file in Windows.
From the windows command prompt:
C:\test>echo %USERNAME%
tim
C:\test>bash.exe
wsluser#computer:/mnt/c/test$ touch foo.txt
wsluser#computer:/mnt/c/test$ exit
exit
C:\test>dir /q C:\test\foo.txt
Volume in drive C is OS
Volume Serial Number is B8BA-E032
Directory of C:\test
2017-06-26 02:06 PM 0 tim foo.txt
1 File(s) 0 bytes
0 Dir(s) 363,224,875,008 bytes free
Notice that bash.exe was started by the tim user, and the C:\test\foo.txt file which was created from WSL is also owned by tim.
You can access the Linux file system using the windows file explorer. It's located in your AppData\Local folder. It's "semi-hidden" but accessible:
C:\Users\[username]\AppData\Local\lxss\rootfs
I am always getting this error. What is the solution ?
As the error message says: your /etc/sudoers file has the wrong permissions.
the normal permissions (on OS X 10.10) are:
$ ls -l /etc/sudoers
-r--r----- 1 root wheel 1293 Sep 19 2012 /etc/sudoers
so get a root shell in some other manner and issue chmod 660 /etc/sudoers
and/or the appropriate chgrp and chown commands.
To get a root shell, it all depends on what you have left as assets.
The failsafe method would be from a recovery partition, but booting in single user mode should be enough in most cases.
Single user mode: boot holding "Command-S"
ref: https://support.apple.com/en-us/HT201573
When I try to change the permissions for a file it doesn't seem to work. chmod says it is changing it but the file permissions remain the same. Can anyone explain what I am doing wrong? Here is a copy of my command line.
~$ sudo chmod -v u+x ex01
mode of 'ex01' changed from 0600 (rw-------) to 0700 (rwx------)
~$ ls -l ex01
-rw------- 1 user user 60297 Feb 6 21:50 ex01
Certain file systems, such as vfat, don't support Unix permissions. The owners and permissions of the files are decided when the file system is mounted. On vfat for example there is an option to set the permissions to whatever you want, and another that sets the execute bit only for .exe, .com, .bat and similar files. See https://www.kernel.org/doc/Documentation/filesystems/vfat.txt