Forward: Mounting Windows SMB File Shares Using Cifs

來源:互聯網
上載者:User

Reference: http://ubuntuforums.org/showthread.php?t=288534

In the world of linux and Samba File Shares, there are essentially two ways to mount your SMB shares. Of course, you can always access your shares via the Places->Network dialog, where you can go to town looking through your shared drives. Of course, this has some major downfalls. Primarily, most applications don't recognize the network folders as legitimately mounted disks (because they're not). In other words, try opening up a shared music file in Audacious (or your favorite music player). Did it work? Well, if you're more clever than me, perhaps. The true way to handle your shared files is by mounting them. Then we'll have a legitimately mounted drive, with which we can do whatever we want.

Like I said, there are two ways to mount your filesystem. The first is the original smbfs, and the latter is the newer and more preferred method of cifs. While I originally used smbfs (it made sense, its name looks just like what I'm trying to mount), today (Nov 16, 2007), when I did the ubuntu system update, everything went crazy. All of a sudden, my smbfs mounted drives ground to a halt - each request took about 1-2 minutes to fulfill. I could still browse the files quickly through Places->Network, but my smbfs shares were crawling.

But then I remembered that there's an alternative, and now that I have it up and running, I can say that it's quite easy and quite fast. Here's what you do:

Firs, we need to install cifs, which comes right alongside smbfs. If you have smbfs, then you have cifs. If you don't, open up a terminal and get it:

sudo apt-get install smbfs

Next, all mounted drives need to mount to some folder on your local drive. I prefer to mount mine in the /media folder, which makes sense, as your cdrom is mounted there along with other drives, including things like external and thumb drives. Type the following, replacing my_share with whatever folder name you want your share to be (this doesn't matter at all, it can be called anything and go anywhere).

sudo mkdir /mount/my_share

Now, while we're going to perform some permanent mounts later (so that the disk mounts after a restart), let's start with a manual mount.

sudo mount -t cifs //192.168.1.102/share_name /media/my_share -o username=theuser,password=thepass,iocharset=utf8,file_mode=0777,dir_mode=0777

Let me explain. The mount -t cifs command simply instructs the system to mount the following parameters via cifs. The next argument: //192.168.1.102/share_name consists of 2 parts. The first is the ip address of the computer with the shares. This can also be "net bios name", but since that was giving me a headache, I simply used the ip address. The second part: share_name is the name of the share on the hosting computer. Under Places->Network, you should see the computer that you are trying to connect to. If you double click into that computer, you will see (you may have multiple) the name of the share (something like my-external-drive perhaps). Use that value in place of share_name.

The next part of the command: /media/my_share is that directory that we created earlier. After the mount is successful, the contents of the share will be accessible via this directory.

Finally, everything that comes after the -o are the options. First, we have the username and password. These should be set to the username and password of the windows computer to which you are trying to connect. For me, my "windows" computer was a windows computer at all, but rather an ubuntu server (we have many types of computers needing to connect to it). In this case, I used the username and password of my ubuntu use. Exact same idea. The things after that shouldn't need modification. They set the charset to utf8 (so that we're nice to foreign character sets), and make the mount read/write.

Now, if it worked, you should see your mount right on the desktop. Browse through it, play music from it, watch movies from it (network speed permitting). Here are some common errors:

  • mount error: can not change directory into mount target... - either you didn't create your /media/my_share directory or specified it wrong in your mount command.
  • mount error 13 = Permission denied - your username and password are being rejected. Try some other combinations
  • mount error 6 = No such device or address - the share_name that you specified in your mount command is not being found on the host computer. Browse the network, find that computer, and check to make sure you see the exact share name.

 

We now have proof of concept, but we want the drive to mount automatically on restart. First, let's unmount the drive so that we can test our remounting of it later. The following should do it.

sudo umount //192.168.1.102/share_name

The share should've disappeared from your desktop. Important, we will use the /etc/fstab file to mount the share by inserting a similar command as above into that file. This file can be read by anyone on your computer, which would mean that anyone could read the username and password you specify for you mount. If you don't care (come on guys, care a little), then simply do the following:

sudo nano /etc/fstab...and add the following to the bottom, updating as necessary://192.168.1.102/share_name /media/my_share cifs username=theuser,password=thepass,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0

For the rest of us who desire a little more security, the following is the clever way of hiding the username and password.

sudo nano /root/.smbcredentialsand enter in the file:username=theuserpassword=thepass

Now, let's make sure only root can read this file:

sudo chmod 700 /root/.smbcredentials

Now, we simply need to replace the username and password portion of the fstab file with a handly credential option.

sudo nano /etc/fstaband make your mount command look like this://192.168.1.102/share_name /media/my_share cifs credentials=/root/.smbcredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0

And we're done. You can now either restart to test, or simple run the following command, which remounts all the drives in the /etc/fstab file that are not currently mounted (very handy):

sudo mount -a

If you saw your share pop up on the desktop, then you're done. Your brand new cifs file share will mount each time you boot up your computer.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.