Soft symbolic link mac permission denied - macos

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

Related

How to delete a file on ubuntu with another user?

I'm trying to create a file with a user. The file should be created in a manner that another user can delete it (I would be fine with just any user being able to delete it).
cd /tmp
> test
chmod 666 test
#make file owned by a different user and group
chown tomcat:tomcat test
rm -r test
Result:
rm: cannot remove 'test': Operation not permitted
What am I doing wrong? How do I have to create that file so another user is able to delete it?
The /tmp directory is a "bit" special. It has the permissions 1777 which sets the sticky bit. You'll see that an ls -l / shows tmp with the permissions:
drwxrwxrwt 25 root root 12288 Aug 3 08:20 tmp/
That t means that it prevents anyone except the owner from removing files. You'll need to use a different directory. Additionally, the -r doesn't make sense for a file.

Shell Script to Move a File Into Another User's Directory?

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.

linux permission denied ./file.sh VS bash file.sh

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.

I can copy file but can not move it from my Mac Terminal

I can copy file but can not move it on my Mac Terminal.
I want to execute following command:
mv /apps/gfss/ipt/files/R2R/Japan_WHT/21940000/DATA.xlsx /apps/gfss/ipt/files/R2R/Japan_WHT/21940000/inprogress/
And I get following error:
mv: rename /apps/gfss/ipt/files/R2R/Japan_WHT/21940000/DATA_21940000.xlsx to /apps/gfss/ipt/files/R2R/Japan_WHT/21940000/inprogress/DATA_21940000.xlsx: Permission denied
However, if I use Finder, I can move it. But I want to do this from Terminal.
But, I am able to copy:
cp /apps/gfss/ipt/files/R2R/Japan_WHT/21940000/DATA.xlsx /apps/gfss/ipt/files/R2R/Japan_WHT/21940000/inprogress/
Wondering what is that I am doing wrong!?
Below is the ls -ltr output:
gfss-apac-ipt2:21940000 admin$ pwd
/apps/gfss/ipt/files/R2R/Japan_WHT/21940000
gfss-apac-ipt2:21940000 admin$ ls -ltr
total 384
-rw-r--r--# 1 alokur wheel 193385 Nov 22 12:09 DATA_21940000.xlsx
drwxr-xr-x+ 2 admin wheel 68 Nov 22 13:08 inprogress
P.S.: Move does not work even when I do chmod 777 inprogress; and I get same error.
I asked this question here, but no luck so far.
Resolved:
I had to delete the folder /apps/gfss/ipt/files/R2R/Japan_WHT/21940000 and recreate it.
Then I cd to /apps/gfss/ipt/files/R2R/Japan_WHT/ and gave permission to 21940000 directory using chmod -R 777 21940000/
I think there was some hidden directory inside 21940000 created by some other user and hence I was unable to do chmod before.
Thanks to Ab Sin for his comments which gave me some directions to investigate.

Unable to make file editable on Mac OS X

I'm trying to edit the httpd.conf file located in /private/etc/apache2, and I can't figure out how to get permission to write
I've done
$ cd /private/etc/apache2
$ sudo chown bdh httpd.conf
$ ls -lash
0 drwxr-xr-x 13 root wheel 442B Jun 7 00:11 .
0 drwxr-xr-x 93 root wheel 3.1K Jun 26 10:51 ..
0 drwxr-xr-x 13 root wheel 442B Jan 3 16:26 extra
24 -r--r--r-- 1 bdh wheel 24K Jun 7 00:11 httpd.conf
...etc...
$ vim httpd.conf
and it says "httpd.conf" [readonly] 677L, 24330C
tried cping to the desktop, but I cant get permission to edit it there either
I'm pretty new to using the terminal, is there some other command I can use?
It is normally unnecessary and undesirable to alter access permissions to edit a file. To edit a file that requires administrator (or other user) privileges without altering the access permissions, use:
sudo -e /private/etc/apache2
Sudo's -e option tells it you want to edit the given file.
This command copies the file and makes it writable by you, tells the editor specified with the SUDO_EDITOR, VISUAL or EDITOR environment variables (they're checked in that order) to edit the file, and when the editor exits, the file is copied back to the original without altering its access permissions.
See the sudo man page for details: x-man-page://8/sudo
The chmod command is what you're looking for I believe: http://en.wikipedia.org/wiki/Chmod
chmod 777 will let anyone read, write or execute for instance.
As richardhsu correctly added, 744 is RWX, R--,R-- and thats probably what you want.

Resources