32

I am using ubuntu and gnome on my computer.

When I open up File Browser, on the left hand rail, I see conveniently a folder called "Work Server". When I mouse over it, the following caption appears "smb://john@69.100.100.1". If I click on that folder, then I can see the contents of that folder. Everything is great.

So now when I open up a terminal/shell, I type in

cd smb://john@69.100.100.1

I get an error saying the directory doesn't exist. How do I enter this directory via shell/terminal?

gparyani
  • 1,881
learningtech
  • 1,311

5 Answers5

32

The reason you can't cd in that share is because cd only works on local filesystems*, you have two ways of solving your problem here:

Use smbclient to browse the share:

smbclient -U john //69.100.100.1/SHARENAME

or mount -t cifs if you want to mount the share locally, note that the mount point must exist as a folder:

sudo mount -t cifs -o user=john,iocharset=utf8,noperm //69.100.100.1/SHARENAME ~/shares/SHARENAME 

Make sure you adapt SHARENAME to match your environnement.

If your login is part of an Active Directory domain you may want to add its name to those commands, with the second one that would be:

sudo mount -t cifs -o user=YOURDOMAIN//john,iocharset=utf8,noperm //69.100.100.1/SHARENAME ~/shares/SHARENAME

* The meaning of "local" here is not straightforward, just keep in mind you can't use normal tools before you mount remote FS locally.

Shadok
  • 4,070
6

Shamelessly borrowed from https://askubuntu.com/questions/101029/how-do-i-mount-a-cifs-share

terminal command is:

sudo mount -t cifs -o username=USERNAME,password=PASSWD //192.168.1.88/shares /mnt/share

note you may need to install cifs-utils

davelupt
  • 227
1

Since it looks like the remote share is already mounted, there's no need to mount it again (sure you can, but do you want to?). Instead you need to find where has it been mounted. Since you're using GNOME, the big chance is it was mounted as gvfsd-fuse. If you're impatient, just try to run this:

ls "/run/user/$(id -u)/gvfs"

and check if you can see the directory where the share has been mounted (you should see something like smb-share:server=remote.server,share=remote-share-name). If you do, then you're done. :-) (Note that id -u or id --user gets your effective user ID — an integer number. If you know it up-front, you can safely replace the parentheses expression with it).

If it failed, you can run findmnt and look for gvfs entries in FSTYPE column. It may look like this:

TARGET                                 SOURCE         FSTYPE          OPTIONS
…
│   └─/run/user/1000/gvfs              gvfsd-fuse     fuse.gvfsd-fuse rw,nosuid,nodev,relatime,user_id=1000,group_id=1000
…

If you see this, check (ls) the path in TARGET column, in that case it's /run/users/1000/gvfs — you should be able to see your already mounted share here.

Cromax
  • 153
1

Although there are other answers that are essentially correct and quite complete, I'm writing this one to also cover the case of Macos.

First of all, in Macos it shouldn't be necessary to run mount as root (unless, of course, you try to mount your remote storage into a "privileged" path).

As noted by @grawity, in Linux it can also be avoided in case you use FUSE to mount your external storage (although that can potentially affect performance).

My steps (for Macos):

# 0. If you manually mounted your external storage through the UI,
#    then unmount/eject it before continuing (this is more relevant
#    in Macos than in Linux).

1. Create the directory where I want to mount my external storage

mkdir -p ~/shared/my-shared-folder

2. (A: without password) Mount the external storage

mount -t smbfs "//username@HOSTNAME_OR_IP_ADDRESS/MySharedFolder" ~/shared/my-shared-folder

2. (B: with password) Mount the external storage

mount -t smbfs "//username:password@HOSTNAME_OR_IP_ADDRESS/MySharedFolder" ~/shared/my-shared-folder

IMPORTANT: Regarding username and password, there is an important detail: They MUST be URL-encoded. That is, if they have "special" characters, be sure to encode them as they would be in a typical URL. You can use some tools to do that.

For example, ! would be encoded as %21.

castarco
  • 111
-1
open 'smb://login:pass@ip/Folder'