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.

  • Which error messages are you getting?
    – nohillside
    Commented Oct 28, 2013 at 17:25

4 Answers 4


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
  • Eek! What if I don't want to store my afp use/pass in a bash script because...well...if one computer is compromised, why give the keys away to another. Plus, that has to be bad practice, right? I guess I'll test if I can be prompted for the user/pass by the script instead. Commented Nov 9, 2018 at 18:05
  • Sure, if you're scripting at the user level then you can prompt for the password and stored it in the variable pass. Then replace "pass" with ${pass}. Commented Nov 11, 2018 at 3:56
  • Yep that makes sense. I was hoping that somehow a call to afp could trigger the user to enter the password, but I guess doing it manually is just as good. Thanks for the reply. :) Commented Nov 12, 2018 at 5:37
  • I tried to do this, and it mounts a volume, however I cannot access the mounted volume. In Finder I get an error message saying I have no permissions, and in the shell I can only cd into the mounted share as root (Even though /Volumes/mount has drwx------ and my username as owner.) What's wrong here? Commented May 20, 2020 at 14:55
  • @fbitterlich My first suspicion would be something wrong on the server end. Have you successfully mounted the volume on another computer? What happens when you mount it using the Finder's "Connect to Server ..." menu item? BTW - Are you still using AFP? These days I'd use SMB. Commented May 21, 2020 at 22:37


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>
  • So smb is the acronym for Sapple Miling Brotocol?
    – klanomath
    Commented Dec 28, 2017 at 16:49
  • Works the same way with Apple Filing Protocol, of course. The answer is just a quote from the linked page. And it's the only valid answer to "how can I do this exact action through the terminal?". mount needs a mount point, so it's not the exact same action. Commented Jan 12, 2018 at 21:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .