User Tools

Site Tools


ubuntu:samba:mount_a_windows_share

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
ubuntu:samba:mount_a_windows_share [2019/12/08 20:13] peterubuntu:samba:mount_a_windows_share [2020/07/15 09:30] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Ubuntu - Samba - Mount a Windows Share ====== ====== Ubuntu - Samba - Mount a Windows Share ======
 +
 +
 +===== Quick Example =====
 +
 +<code bash>
 +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
 +</code>
 +
 +----
 +
  
 ===== Command line basic syntax ===== ===== Command line basic syntax =====
Line 8: Line 18:
 mount -t cifs -o username=USERNAME,password=PASSWD //192.168.1.88/shares /mnt/share mount -t cifs -o username=USERNAME,password=PASSWD //192.168.1.88/shares /mnt/share
 </code> </code>
 +
  
 ---- ----
Line 40: Line 51:
 uid=1000(user_name) gid=1000(user_name) groups=... uid=1000(user_name) gid=1000(user_name) groups=...
 </code> </code>
 +
  
 ---- ----
  
-Make the following entry in your /etc/fstab file :+**__dir_mode file_mode__**
  
-//server_name/share_name /mount_path cifs defaults,uid=1000,gid=1000 0 0 +Setting the uid or gid is fine if you are the only user of the system.
- +
----- +
- +
-Now when the share is mounted all files and folders will appear as the user with uid 1000.+
  
-This 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.+On a multiuser system this is problematic as other users will still be denied.
  
-Another option is to use dir_mode / file_mode to give everyone access:+Therefore use **dir_mode / file_mode** to give everyone access:
  
 <code bash> <code bash>
Line 59: Line 67:
 </code> </code>
  
-which will look like: 
- 
-<file bash /etc/fstab> 
-//server_name/share_name /mount_path cifs defaults,dir_mode=0777,file_mode=0666 0 0 
-</file> 
 </WRAP> </WRAP>
  
-===== Command line mount =====+---- 
  
 <code bash> <code bash>
-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+sudo mount -t cifs -o username=${USER},password=${PASSWORD},uid=$(id -u),gid=$(id -g),forceuid,forcegid, //server-address/folder /mount/path/on/ubuntu
 </code> </code>
 +
  
 ---- ----
 +
  
  
Line 79: Line 85:
 ===== fstab persistent mount ===== ===== 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.
  
-Permanently mount the shares so that they will be available after reboot.  If the system complains add the 'noauto' parameter.+==== Edit the host file ====
  
 Edit your **/etc/hosts** file and add the hostname and IP address of the windows share or file server. Edit your **/etc/hosts** file and add the hostname and IP address of the windows share or file server.
Line 91: Line 97:
 </file> </file>
  
-Next create mount points in /mnt for each windows share.+---- 
 + 
 +==== Create mount points ==== 
 + 
 +Create mount points for each windows share.  For example:
  
 <code bash> <code bash>
Line 99: Line 109:
 </code> </code>
  
-Make sure you have cifs installed.+----
  
-Edit **/etc/fstab** and add a line for each windows share, see examples:+==== Edit /etc/fstab ==== 
 + 
 +Edit **/etc/fstab** and add a line for each windows share.  For example:
  
 <file bash /etc/fstab> <file bash /etc/fstab>
Line 108: Line 120:
 //remote_machine/video/ /mnt/video 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
 </file> </file>
 +
 +<WRAP info>
 +** NOTE:** If the system complains add the 'noauto' parameter.
 +</WRAP>
  
 ---- ----
  
-==== Mount the shares ====+=== Mount the shares ===
  
 <code bash> <code bash>
 sudo mount -a sudo mount -a
 </code> </code>
 +
 +or Reboot.
 +
 +----
 +
 +===== Extended fstab settings =====
 +
 +Make the following entry in your /etc/fstab file :
 +
 +<file bash /etc/fstab>
 +//server_name/share_name /mount_path cifs defaults,uid=1000,gid=1000 0 0
 +</file>
 +
 +Now when the share is mounted all files and folders will appear as the user with uid 1000.
 +
 +----
 +
 +<WRAP info>
 +**__FURTHER INFORMATION:__** 
 +
 +
 +**__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:
 +
 +
 +<file bash /etc/fstab>
 +//server_name/share_name /mount_path cifs defaults,dir_mode=0777,file_mode=0666 0 0
 +</file>
 +
 +</WRAP>
 +
 +----
 +
 +===== Extende fstab to assign full permissions to newly created files and directories =====
 +
 +Add these lines to /etc/smb.conf on the server:
 +
 +<file bash /etc/smb.conf>
 +...
 +create mask = 0666
 +force create mode = 0666
 +directory mask = 0777
 +force directory mode = 0777
 +...
 +</file>
 +
 +This gives 0777 permission to every samba users in the write list for new created directory or files.
 +
 +----
 +
 +===== Hide Credentials =====
 +
 +Setup a credentials file so you don't need to enter your password in the command; causing it to be stored in your command history in plain-text) or at the prompt (a nuisance).
 +
 +<code bash>
 +sudo mount -t cifs //nas/docs /media/peter/nas_docs -o vers=3.11,credentials=/home/peter/.ssh/.smb_nas
 +</code>
 +
 +Note the **credentials option**
 +
 +<file bash /home/peter/.ssh/.smb_nas>
 +username=peter
 +password=[REAL PASSWORD]
 +domain=WORKGROUP
 +</file>
  
ubuntu/samba/mount_a_windows_share.1575835988.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki