How to mount remote windows partition (windows share) under Linux

Posted on in Categories CentOS, File system, Howto, Linux, RedHat/Fedora Linux, Suse Linux, Sys admin, Tip of the day, Ubuntu Linux, UNIX, Windows, Windows server last updated April 26, 2004

All files accessible in a Linux (and UNIX) system are arranged in one big tree, the file hierarchy, rooted at /. These files can be spread out over several devices. The mount command serves to attach the file system found on some device to the big file tree.

Use the mount command to mount remote windows partition or windows share under Linux as follows:

Procedure to mount remote windows partition (NAS share)

1) Make sure you have following information:
==> Windows username and password to access share name
==> Sharename (such as //server/share) or IP address
==> root level access on Linux

2) Login to Linux as a root user (or use su command)

3) Create the required mount point:
# mkdir -p /mnt/ntserver
4) Use the mount command as follows:
# mount -t cifs //ntserver/download -o username=vivek,password=myPassword /mnt/ntserver

Use following command if you are using Old version such as RHEL <=4 or Debian <= 3: # mount -t smbfs -o username=vivek,password=D1W4x9sw //ntserver/download /mnt/ntserver

5) Access Windows 2003/2000/NT share using cd and ls command:
# cd /mnt/ntserver; ls -l
Where,

  • -t smbfs : File system type to be mount (outdated, use cifs)
  • -t cifs : File system type to be mount
  • -o : are options passed to mount command, in this example I had passed two options. First argument is password (vivek) and second argument is password to connect remote windows box
  • //ntserver/download : Windows 2000/NT share name
  • /mnt/ntserver Linux mount point (to access share after mounting)

See also:

Updated for accuracy on Aug-8-2007, 8:19PM.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

68 comment

  1. Hi,

    I have used dual boot system, using Windows 2001 & Red Hat Linux.
    1) How make them to speak or share etch other files.
    2) How I login Linux & windows without restarting the computer. There is any utility for this.

    Regards,
    Nandkishor

  2. I tried this command on my Ubuntu system but got the following error:
    mount: wrong fs type, bad option, bad superblock on //server_name/Ubuntu_Backups,
    missing codepage or other error
    In some cases useful info is found in syslog – try
    dmesg | tail or so

    I also tried nfs but still no good. I have a windows server 2003 machine I am sharing to the ubuntu box.

      1. Thanks a million!!!!

        I had exactly same error and I was not able to find a solution. Then I went through the comment, see your comment and… it works! so simple! like a charm!

        Thanks a lot!

  3. i did a \ and din work (nothing happened, it just stucked)

    added –verbose and saw some external ip it’s trying to connect to.

    in the end, i did \192.168.0.164 and it worked cheerfully….

  4. Hi all,
    I have tried the above approach, but it didn’t work. I tried the following approach and it worked

    Step 1: # mkdir -p /mnt/ntserver

    Step 2: Check what the Windows server is providing with smbclient # smbclient –L -W -U

    Eg. # smbclient -L muralidhar12 -W windom -U murali
    password:

    If the command executes succesfully you will see the name of the shared folder of Windows

    Step 3: Mounting the Windows Shared folder
    # mount -t cifs : -ousername=,domain=

    Eg. # mount -t cifs CORESERVER:F$ /mnt/temp -ousername=nimda,domain=WINLAB
    Password:

    If all the steps carried out well, then you will be able to access the share folder.

    Step 4: Now every time you restart the system, you have to carry out the Step 3. If you wish you can mount the share folder at startup too. To do this, add the following entry to your /etc/fstab file

    MachineName:ShareFolderName /mnt/MountFolderName cifs username=UserName,domain=DomainName,password=Password 0 0

    Eg.

    TomsComputer:MyShare /mnt/winshare cifs username=tom,domain=work,password=secret 0 0

    1. Hi,

      I have one shared folder in my remote desktop (windows XP), I am working in linux server through terminal in my pc. I want to mount that folder to linux server. can you help me.

      Thanks in advance……

  5. This may useful when any one Got this error like

    mount -t cifs //hostname/share /mnt/temp -o username=someuser,password=somepassword
    mount error 13 = Permission denied
    Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)

    Do like this:
    =========

    mount -t cifs //amit99.indusa1234.com/abc /mnt/ntserver -o username=indusa1234.com/amitgandhi,password=”tost123490″

    This will work… Enjoy

  6. This topic is discussed extensively at:

    The digest is the following.
    Win XP/2003 has built-in firewall that restricts access to SMB share ports (TCP 139, 445) by unusual and non-documented way . Win-to-Win connection to those ports is allowed, while Samba-to-Win is disallowed.
    Remedy variants:
    1) Disable built-in firewall (this is very bad solution)
    2) Disable built-in firewall, install “independent” firewall (this is a good solution, but free firewall suites are not available for Win2003 server)
    3) Modify rule for built-in Windows firewall using several mouse clicks (I’d recommend it).
    For this, (a) open list of firewall exceptions; (b) locate “File and Print Sharing” item in the list of exceptions and click on its line to select this item; (c) press button “Edit…”; (d) select row “TCP 139”; (e) press button “Change Scope…”; (f) select item “Any computer”.
    (g) Press OK; (h) repeat steps d-g for “TCP 445”. Save settings. Be happy.

  7. Thank You!! Ive been trying off and on for 2 weeks to get my ubuntu machine to access my windows shares and no luck. Trying the GUI and command line smb connect commands, everything said login failure and/or access denied when I would enter windows credentials. This worked like a charm! As a side note, I was able to setup samba sharing rather quickly and have been able to browse the samba shares from my windows box, but not the other way arround. Not sure what the difference is between the samba GUI and this method, just glad it works (Would love to know why if anyone cares to share).

    Thanks,

    al

  8. Thank you very much for your clear instructions on the various mount options.

    Do you know the settings to allow a linux mount to go through a windows firewall.
    i.e. the setting on the firewall.

    Regards

    Noel

  9. i got samba installed at linux, anything to install in windows?

    tried that but got error:
    mount: wrong fs type, bad option, bad superblock on //MRCM/downloads,
    missing codepage or other error
    In some cases useful info is found in syslog – try
    dmesg | tail or so

    dmesg shows:
    CIFS VFS: cifs_mount failed w/return code = -22

    tried search above error but solution found not working

  10. “-o : are options passed to mount command, in this example I had passed two options. First argument is password (vivek) and second argument is password to connect remote windows box”

    Hi – I think you need to amend the first argument to “username”, not “password”.
    Otherwise great tutorial!
    – Jason

  11. hmmm… I see, the smbfs command is still working here
    I’m using Ubuntu Server and everything works fine.

    this is the example command i used before
    referenced from your articles as well.
    [quote]
    $> mount -t smbfs //myTargetWindowsIP/aDirectory /home/myOwnLinuxDirectory -o username=windowsUserName,password=windowsPassword
    [/quote]

    Enter! Done!

    great thanks!

    but, anyway, is this permanent?
    is it at the time we restart the Linux machine,
    we need to RE MOUNT it again?

  12. Nice post, it worked, but what I need is to used the shared content on windows as my repo for my ubuntu, as I read that smb protocol isn’t supported in the /etc/apt/sources.list I figure that mountin the filsystem an put in the sources.list as

    deb file:///mnt/ubuntu lucid restricted main

    but it doesn’t work on apt-update I get this error

    Failed to fetch file:/mnt/ubuntu/dists/lucid/restricted/binary-i386/Packages.gz File not found

    and some others like this, so how can I use the repository in this way? some ideas?
    thanks

  13. To all with the following error: CIFS VFS: cifs_mount failed w/return code = -22

    You must install samba-client or the kernel will not know the fs type.

    Under CentOS/Redhat variants: yum install samba-client

    Note: samba (the server) is not the same as samba-client.

  14. In my organization we have a windows shared folder that people can drop files too.
    I want to access it from my Debian.
    The Internet is full with guides that show how to do it, but with and .
    In our organization they don’t require a user and pass to access this folder, and the GUI tool of gnome, expects me to type in a user name and pass, but there simply isn’t.

    So I tried with the following command:
    sudo mount -t cifs //iif00/Institut /home/oz/win/

    I get the following error:
    mount: wrong fs type, bad option, bad superblock on //iif00/Institut,
    missing codepage or helper program, or other error
    (for several filesystems (e.g. nfs, cifs) you might
    need a /sbin/mount. helper program)
    In some cases useful info is found in syslog – try
    dmesg | tail or so

    dmesg tail shows:
    [ 152.030382] CIFS VFS: cifs_mount failed w/return code = -22

    I Installed samba-client via apt-get and restarted the computer, but I still get an error.

    Ideas would be great !
    Thanks in advance.

  15. Well, I helped myself via google:

    Solution to “cifs_mount failed w/return code = -22″

    When trying to mount my network drive from campus at home I received the following message in dmesg:
    view source
    print?
    1 CIFS VFS: cifs_mount failed w/return code = -22

    Well it turns out that I needed to have the smbfs package installed. This quickly solved my problem.
    view source
    print?
    1 sudo apt-get install smbfs

  16. i have use redhat linux 5 on hyper-v,,then configure the NIS server & create in users..first i wont access user profile every users from window server 2008 create in AD,, i wont my window domain users profile mount at my linux NIS users….am waiting

  17. i have use redhat linux 5 on hyper-v,,then configure the NIS server & create in users..first i wont access user profile every users from window server 2008 create in AD,, i wont my window domain users profile mount at my linux NIS users….

    am usesing this command mount -t cifs //ntserver/baljinder -o username=baljinder,password=myPassword /NIS/User/baljinder…but only root user read & wright everything not a baljinder user……pllz tell me any

  18. I actually tried this in mt linux terminal-

    mkdir /mnt/ntserver
    mount -t cifs //serverip/ -o username=user,password=password /mnt/ntserver

    and it didn’t work. Am I missing something here?

  19. -o : are options passed to mount command, in this example I had passed two options. First argument is ”””’password ”””'(vivek) and second argument is password to connect remote windows box

    above line i think its username not password,

  20. Hi,
    my smb client is windows 7, fews are in the workgroup and fews within domain. I’m able to access smb share from windows 7 client. but not able to access windows 7 share from smb server. I’m using RHEL5.
    Using the below command.
    # mount -t cifs //servername/sharename /mnt/mountpoint
    -o username=myusername,password=mypassword
    Error getting: “error “mount error 110 = Connection timed out”.
    please suggest.

  21. These mount procedures work for me but after mounting you have be be root to do any thing. Can’t even do an ls without sudo prefacing. Also I can’t chown or chmod, even as root.

    Any ideas?

    Thanks,
    Ken

  22. Hi all, I have Windows7 host and Backbox as guest using VirtualBox. I want to Access my Windows D drive in Backbox.

    So, I ran the command on backbox

    [email protected]:/home/ranjeet# mount -t cifs //ntserver/D -o username=ranjeet,password=mypassword /mnt/server

    And output was –

    mount: wrong fs type, bad option, bad superblock on //ntserver/D,
    missing codepage or helper program, or other error
    (for several filesystems (e.g. nfs, cifs) you might
    need a /sbin/mount. helper program)
    In some cases useful info is found in syslog – try
    dmesg | tail or so

    What should I do?

  23. Im trying to mount to my share on my windows 7 pc using
    mnt -t cifs //Ipaddress /share name /mnt -o username=domain/administrator.name
    but comes up mnt not command when I use mount -t cifs //Ipaddress /share name /mnt -o username=domain/administrator.name

    displays all the mount functions and want proceed any suggestions

  24. Hi,

    Happy New Year!!!

    I am trying to mount my share on win 2003, from zyxel NSA320, and I get message:
    ls: cannot open directory .: Value too large for defined data type

    Does anybody knows what is the problem?

  25. I installed cifs-utils in my ubuntu 9.04 and use command

    “mount -t cifs //192.168.0.5/rd2 //mnt/samba -o username=rd2,password=,codepage=cp950”, where cp950 is Chinese codepage at Windows.

    It works fine. I did the same at Ubuntu 14.04, it doesn’t work.

    I used command “mount -t cifs //192.168.0.5/rd2 //mnt/samba -o username=rd2,password=,codepage=cp950”, It showed “mount error(22): Invalid argument”.

    I used command “mount -t cifs //192.168.0.5/rd2 //mnt/samba -o username=rd2,password=”, It showed “mount error(13): Permission denied”.

    I used command “”mount -t cifs //192.168.0.5/rd2 //mnt/samba -o username=rd2”, I was prompted to input password. After inputting password, It showed “mount error(13): Permission denied”.

    How come?

  26. From a linux box, I mounted a Windows share using cifs.

    The intend was to “locally” use rsync to backup my windows machine. The command line used to mount the Windows drive is something like:

    mount \192.168.1.74share /cifs1 -t cifs -o noserverino,iocharset=utf8,ro

    Please also note that the drive attached to the linux box is formatted ntfs.

    When doing a sample backup, rsync was always re-copying the directories (names), but not the files. After looking more closely at the “ls -lh ” output at both ends, I noticed that on the linux side the size of the directory level is always 0:

    [email protected]:/tmp/mnt/RT-1080/tmp# ls -lh
    drwxrwxrwx 1 TTT-Admi root 0 Feb 8 12:14 DeltaCopy

    but the size of the directory level on the cifs side was always different from 0:

    [email protected]:/cifs1/temp/Rsync-Packages# ls -lh

    drwxr-xr-x 1 TTT-Admi root 8.0K Feb 8 12:14 DeltaCopy

    This difference explains why rsync was always recopying directories, but not recopying the folders(which was correct, folder sizes and time stamps being the same on both ends).

    > rsync -av /cifs1/Temp/Rsync-Packages/DeltaCopy /mnt/RT-1080/tmp/rsync
    -av /cifs1/Temp/Rsync-Packages/DeltaCopy /mnt/RT-1080/tmp/

    Is a directory supposed to “have a size” or not ? What should I do to solve this discrepancy ?

Leave a Comment