How to connect to a network share via command line

I'm having trouble with learning how to connect to a network share via the command line. I was in a situation recently where I had to do this via Single User mode.

Okay. So the file system is read only. So I type:

"/sbin/mount -wu /"

This makes / read/write.

Then I have to create a mount point. I don't really understand this. Anyway, I type:

"mkdir /volumes/test"

So now I have my mount point. Then what? Do I change directory to test?

"cd /volumes/test"

Now I'm in "test".

What do I type next? I'm trying to mount an afp share. I've searched online and found confusing/conflicting information:

mount -t afp afp://username:password@domain-or-ip/ShareName/Volumes/ShareName

Or:

mount -t afp //user@server/sharename share

I'm confused.

iMac G5 (iSight) 20in 2.1Ghz 1.5 GB RAM 250 GB, Mac OS X (10.5.8), Soundsticks

Posted on Dec 24, 2009 8:18 PM

Reply
14 replies

Dec 25, 2009 2:30 AM in response to McToast

The syntax for mounting afp drives:
usage: mount_afp [-o option1[,option2...]] 
afp://[username:password]@rhost[:port]/volume node

Also from the mount_afp manual:

node Path to mount point, which must be a directory that the user has
write permissions for.

So the first option has to be modified to:
mount -t afp afp://username:password@domain-or-ip/ShareName/Volumes/ShareName /Volumes/test

Since the mount path is absolute it doesn't matter if your current working directory is different.

Dec 25, 2009 3:43 AM in response to hungryjoe

Hi,

My apology, I am just wondering, about what you wrote

hungryjoe wrote:
So the first option has to be modified to:
mount -t afp afp://username:password@domain-or-ip/ShareName/Volumes/ShareName /Volumes/test

Since the mount path is absolute it doesn't matter if your current working directory is different.



Shouldn't it be
mount -t afp afp://username:password@domain-or-ip/ShareName/ /Volumes/test


or

mount -t afp afp://username:password@domain-or-ip/ShareName/pathtoFolder /Volumes/test2


Because ShareName is already pointing to a /Volumes/Path/SharedFolder at the afp server...
or am I wrong and there are more posibilities?

Thank you

Dec 25, 2009 9:59 AM in response to McToast

If I do this from within terminal.app instead of Single User Mode, do I need to use "sudo"? Also, let me see if I got this right. So let's say my company is pretendco.com. Our search domain is ny.pretendco.com (my company is in New York and that is our actual search domain with the real name subsituted).

Okay. So I type:

mount -t afp afp://username:password@ny.pretendco.com/servername/volume/ /volumes/test

It would not be the following? Or would the following be correct also?

mount -t afp afp://username:password@servername.ny.pretendco.com/volume /volumes/test

Is that correct?

Also, the /volumes/test is telling it where the mount point is? Why can't the mount point just be /volumes? Why do I have to create a new volume in /volumes?

Dec 25, 2009 10:49 AM in response to McToast

Hi,

Nop, no volume name, so far as I know you cant share a Volume by it self, it will need to be always a share.

You can share a volume, but then you give it a share name, maybe or not the same as the /volumes/MyDisk name ( HD at server ).

MyDisk ( mounted f.e as /Volumes/MyDisk on the server) and shared as 'MyDisk'
But lets say I give my 'MyDisk' a share name of 'NewAmsterdam' name instead of 'MyDisk'

then the share is available as f.e. host.domain.tld/sharename

in this case it could be ny.pretendco.com/NewAmsterdam ( depends how your host is setup in the prentendo domain, then yes you have to add the server name )


mount -t afp afp://McToast:password@servername.ny.pretendco.com/NewAmsterdam /volumes/OldAmstel


the mount point doesn't need to be the same name, but for clarity make the names clear-cut and stable for live

So you have to know the share name what that server provides!

But you don't mount Volumes, you mount a share as a volume from the client point of view.

You can mount a folder inside a share

mount -t afp afp://MCToast:password@ny.pretendco.com/NewAmsterdam/McToastFolder/ /Volumes/McToastFolder


{quote}
Also, the /volumes/test is telling it where the mount point is? Why can't the mount point just be /volumes? Why do I have to create a new volume in /volumes?
{quote}
/Volumes separates the disks/shares from the root drive / . Otherwise, I guess, the start disk will get confused. What if the share name is Users? How else will you go into the Folder structure?

I believe that NFS: can do mount into a folder on the /

HTH

Disclaimer: If I am correct!!

Ps.
NY = New Amsterdam, Amsterdam = Old City with river Amstel, Old Amstel = Old Beer 🙂

Dec 25, 2009 1:39 PM in response to McToast

Hi.

Nothing is working for me. Ugh. So frustrating. This is what I do/what happens:

I connect to my corporate network via VPN.

*From the GUI:*

I press command+k and get the connect to server box.
I type: afp://nycpretendoco-groups, then click connect.

I then authenticate.

Now a box pops up asking me to select the volume I want to mount. There are seven volumes (shares, but volumes from the client's point of view, as you say).

I select the volume, ISStaff.

ISStaff mounts on my desktop.

Okay. Eject ISSTaff and now try from command line.

*From the Terminal:*

I type: mkdir /volumes/test

Press Return.

I then type: mount -t afp afp://username:password@nycpretendco-groups.ny.pretendco.com/ISStaff /volumes/test

Press Return.

Then...nothing happens.

The next line in the terminal app becomes this: >|

It just sits there and does nothing, and it never returns me to a command prompt. It never connects to anything (that I can tell).

Dec 25, 2009 2:07 PM in response to McToast

McToast wrote:

Now a box pops up asking me to select the volume I want to mount. There are seven volumes (shares, but volumes from the client's point of view, as you say).


Wait, only when you mount them to a /Volumes/xxxx.
Because you can mount it to a folder like /Volumes/NewYork/City/MyPersFolder

McToast wrote:
I select the volume, ISStaff.

ISStaff mounts on my desktop.

Okay. Eject ISSTaff and now try from command line.

*From the Terminal:*

I type: mkdir /volumes/test

Press Return.

I then type: mount -t afp afp://username: password@nycpretendco-groups.ny.pretendco.com /ISStaff /volumes/test

Press Return.


Did you try mount -t afp afp://username:password@nycpretendco-groups/ISStaff/ /volumes/test

If it doesn't work do a ping to ( using the terminal )
nycpretendco-groups
nycpretendco-groups.ny.pretendco.com
ny.pretendco.com

If you have problems then I guess you have a DNS problem and should use an IP address.

Good luck, This is al I know.

Dec 25, 2009 4:33 PM in response to Obj-D

I did try "mount -t afp afp://username:password@nycpretendco-groups/ISStaff/ /volumes/test" after you mentioned it but still nothing.

I was able to ping nycpretendco-groups and got back a valid IP address for the server but no matter what I try, the next line after I hit return becomes >| and sits there forever.

Maybe after the holiday someone else will stumble upon this and have some ideas. There's got to be something missing or wrong somewhere.

Thanks for your help. Happy Holidays.

Dec 25, 2009 7:24 PM in response to McToast

SUCCESS!!!!!!

I finally got it to mount using terminal.

First I typed:

"mkdir /Volumes/ISStaff"

Pressed Return, then typed:

"mount_afp -i afp://username@nycpretendco-groups/ISStaff /Volumes/ISStaff"

Pressed Return, terminal returns with:

Password:

Then you type your password invisibly, press Return.

ISStaff mounts on desktop.

Type:

umount /Volumes/ISStaff

...to unmount.

🙂 🙂 🙂

-i equals interactive mode, prompting you for your password if you did not supply it in the URL.

For some reason, when I typed "mount_afp afp://username:password@nycpretendco-groups/ISStaff /Volumes/ISStaff" it wouldn't work and after pressing return I would get the >| and the terminal would just sit there. I don't know why it would do that, but I prefer interactive mode anyway, because it keeps your password private.

Also, using "mount -t afp" never worked for me either, only the "mount_afp" command.

Using sudo was never necessary either. I kept reading that you had to do all this using sudo, but it never was the case when I was doing it.

Dec 26, 2009 1:06 PM in response to hungryjoe

Hungryjoe -

I think you may be on to something about my password. I am thinking my password was to blame for
"mount -t afp afp://username:password@nycpretendco-groups/ISStaff /Volumes/ISStaff" not working.

My password contains an apostrophe in it, and when you enter it in the password field in the GUI or invisibly using interactive mode in the CLI, it's okay, but it messes up the URL for the share when you have to spell it out there.

That's my theory anyway.

Dec 26, 2009 2:14 PM in response to McToast

"mount -t afp afp://username:password@nycpretendco-groups/ISStaff /Volumes/ISStaff" not working.

My password contains an apostrophe in it, and when you enter it in the password >field in the GUI or invisibly using interactive mode in the CLI, it's okay, but >it messes up the URL for the share when you have to spell it out there.

The mount command would be processed by the command line interpreter. The command line interpreter assume a quote mark starts a quoted field. You need to escape the quote mark. Example.

mount -t afp afp://username:pass\'word@nycpretendco-groups/ISStaff /Volumes/ISStaff

see:
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect0303.html

Dec 26, 2009 2:40 PM in response to rccharles

rccharles-

Indeed, my password was the problem. I tried it following your instructions, and it worked. I always had a vague idea in the back of my head that the apostrophe in my password was the issue, but was reluctant to mention it until hungryjoe mentioned unescaped quotes. I'm glad it's all solved, and I've learned two methods here.

Thanks!

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to connect to a network share via command line

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.