Connecting to password protected AFP server from terminal

afpfile-sharingmountNetworkpassword

I have one Mac set up with file sharing on the desktop, and I am trying to connect to it from my other Mac from the Terminal. I made a folder mount in /Volumes/, then I used the following command.

sudo mount -t afp afp://user:pass@ipaddress/Desktop /Volumes/mount

(obviously I changed the user/pass/ip to the correct information)

Though whenever I try to access it, it says I do not have permission. When I access it through Finder with the same username and password, it works perfectly fine.

Is there any reason this is not working?

Edit – If I run the ls command with sudo I can access the files. So update to the question:

Is there a way to change the ownership of the Volume? chown is throwing the error Operation not permitted, even with sudo.

Best Answer

To mount a share in Terminal use the following commands:

mkdir /Volumes/mount
mount -t afp afp://user:pass@ipaddress/Desktop /Volumes/mount

This works because the folder /Volumes is world read & writable.

If you use sudo mkdir /Volumes/mount mount has the following permissions:

drwxr-xr-x+ 2 root  admin  -       68  8 Mär 02:40 . <- mount
drwxrwxrwt@ 5 root  admin  hidden 170  8 Mär 02:40 .. <- /Volumes

and the only possible command to mount a share is:

sudo mount -t afp afp://user:pass@ipaddress/Desktop /Volumes/mount

because you are not allowed to "write" (=mount) to the folder mount as non-root user.

with the following result:

drwx------  1 root  wheel  -        264  8 Mär 02:38 . <- mount (the share "Desktop")
drwxrwxrwt@ 5 root  admin  hidden   170  8 Mär 02:42 .. <- /Volumes

and you can't even open (=read) the folder with your user.

If you create the mount folder with mkdir /Volumes/mount the permissions looks like this:

drwxr-xr-x+ 2 user  admin  -       68  8 Mär 02:42 . <- mount
drwxrwxrwt@ 5 root  admin  hidden 170  8 Mär 02:42 .. <- /Volumes

After mounting the share with:

mount -t afp afp://user:pass@ipaddress/Desktop /Volumes/mount

the permissions look like this:

drwx------  1 user  staff  -        264  8 Mär 02:38 . <- mount (the share "Desktop")
drwxrwxrwt@ 5 root  admin  hidden   170  8 Mär 02:42 .. <- /Volumes