This is an old revision of the document!
Table of Contents
Ubuntu - Samba - Mount a Windows Share
Quick Example
sudo mount -t cifs -o username=peter,password=xxxxxxxxxxxxxxxxxxxx,uid=peter,gid=peter,forceuid,forcegid,vers=2.1 //192.168.1.5/Docs /home/peter/Documents/nas_docs
Command line basic syntax
The most basic mount options is:
mount -t cifs -o username=USERNAME,password=PASSWD //192.168.1.88/shares /mnt/share
Extended command line mount
If the basic mount does not work, you may need to use extended features
mount -t cifs -o username=USERNAME,password=PASSWD,iocharset=utf8,file_mode=0777,dir_mode=0777 //192.168.1.88/shares /mnt/share sudo mount -t cifs -o username=${USER},password=${PASSWORD},uid=$(id -u),gid=$(id -g),forceuid,forcegid, //server-address/folder /mount/path/on/ubuntu
where:
- USERNAME The uid of the user who will own all the files and directories in the share.
- PASSWD the password of the USERNAME user.
- iocharset=utf8
- file_mode
- dir_mode
FURTHER INFORMATION:
USERNAME: By default all the files and directories will be owned by the uid of the process or by root. You can force it otherwise.
sudo id user_name
If, for example, the user id is 1000 then you can use the following…
uid=1000(user_name) gid=1000(user_name) groups=...
dir_mode / file_mode
Setting the uid or gid is fine if you are the only user of the system.
On a multiuser system this is problematic as other users will still be denied.
Therefore use dir_mode / file_mode to give everyone access:
dir_mode=0777,file_mode=0666
which will look like:
- /etc/fstab
//server_name/share_name /mount_path cifs defaults,dir_mode=0777,file_mode=0666 0 0
fstab persistent mount
Quick basic example of a cfis mount entry in fstab to connect to shares on a Windows file server or NAS device.
Permanently mount the shares so that they will be available after reboot. If the system complains add the 'noauto' parameter.
Edit your /etc/hosts file and add the hostname and IP address of the windows share or file server.
- /etc/hosts
... 192.168.1.5 NAS ...
Next create mount points in /mnt for each windows share.
mkdir /mnt/public mkdir /mnt/media mkdir /mnt/video
Make sure you have cifs installed.
Edit /etc/fstab and add a line for each windows share, see examples:
- /etc/fstab
//remote_machine/public/ /mnt/public cifs username=peter,password=mypassword,iocharset=utf8,sec=ntlm 0 0 //remote_machine/media/ /mnt/media cifs username=peter,password=mypassword,iocharset=utf8,sec=ntlm 0 0 //remote_machine/video/ /mnt/video cifs username=peter,password=mypassword,iocharset=utf8,sec=ntlm 0 0
Make the following entry in your /etc/fstab file :
- /etc/fstab
//server_name/share_name /mount_path cifs defaults,uid=1000,gid=1000 0 0
Now when the share is mounted all files and folders will appear as the user with uid 1000.
dir_mode / file_mode
Setting the uid or gid is fine if you are the only user of the system.
On a multiuser system this is problematic as other users will still be denied.
Therefore use dir_mode / file_mode to give everyone access:
- /etc/fstab
//server_name/share_name /mount_path cifs defaults,dir_mode=0777,file_mode=0666 0 0
</WRAP>
Mount the shares
sudo mount -a