Question

I want to mount an external drive, connected on computer A, to computer B.

I am able to access and mount the drive by connecting to the server through Finder (Command-K), but how can I do this exact action through the terminal? I've been using several formats of mount and mount_afp but nothing seems to work. Something along the lines of:

mount_afp -i afp://user:pass@ipaddress/Volumes/SharedDrive /Volumes/Shared

In Finder, I just type the IP of the Mac connected to the drive, input credentials, and mount the selected drive...but it's not working by simply entering the afp://ipaddress, just like the 'Connect Server' command through Finder, in the terminal.

How do I do the same connection with a bash command? The end result will be the mounted drive on B.

Was it helpful?

Solution

A couple of things you need to be aware of.

First - the AFP URL needs to contain the name of the share - not it's location on the server. Second, the mount point must be an empty directory that you have write permission to. So your commands might be :-

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

OTHER TIPS

Try:

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

After some trial and error, I believe I've found a technique that works. First, the mount point must be created with the current user having permission to it:

$ NAME=(name of remote volume)
$ HOST=(hostname of server)
$ MOUNT=/Volumes/$NAME
$ sudo mkdir $MOUNT; sudo chown $USER $MOUNT

Then, without sudo, create the mount point using afp_mount:

$ mount_afp -o quarantine afp://$USER@$HOST._afpovertcp._tcp.local/$NAME $MOUNT

In my experience, this created the mount with properties identical to those created by the UI and did not require passing a password (so was able to re-use credentials already saved in the session).

Since I use the xonsh shell, I wrote this routine for my profile script to automate this step:

def connect_share(name, host='myserver'):
    username = $USER
    mount = f'/Volumes/{name}'
    sudo mkdir @(mount)
    sudo chown $USER @(mount)
    url = f'afp://{username}@{host}._afpovertcp._tcp.local/{name}'
    mount_afp -o quarantine @(url) @(mount)

See https://apple.stackexchange.com/a/171822/154516 and comments for:

open smb://<user>:<password>@server/<Volume>
Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top