User Tools

Site Tools


networking:linux:linux_smb

Differences

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

Link to this comparison view

Next revision
Previous revision
networking:linux:linux_smb [2014/01/25 10:12]
gcooper created
networking:linux:linux_smb [2018/01/15 12:08] (current)
gcooper
Line 1: Line 1:
 ====== Mounting SMB (Windows) Shares on Linux ====== ====== Mounting SMB (Windows) Shares on Linux ======
 +
 +===== Newer Distros =====
 +
 +<file>
 +sudo apt-get install cifs-utils
 +</file>
 +
 +<file>
 +sudo mkdir /mnt/sharename
 +sudo mount -t cifs //server/sharename /mnt/sharename -o rw,_netdev,username=<smbusername>,password=<smbpassword>,domain=<domain>,uid=<username>,gid=<usergroup>,iocharset=utf8,file_mode=0777,dir_mode=0777
 +</file>
 +
 +:!: If name resolution fails, try the IP address of the server.
 +
 +:!: If you need multiple users to access the share, you'll need to work with ''gid'' and group memberships.  Otherwise, you can usually just use the <username> in the ''gid'' field.
 +
 +===== Older Distros =====
  
 Windows (SMB, CIFS) shares can be accessed in various ways from a modern Linux desktop, but if you want everything (such as rsync) to work (most) all of the time, it's best to just mount the Windows share to a local mountpoint. Then, regardless of the type of access you desire, you just access the filesystem as if you were browsing local files. Windows (SMB, CIFS) shares can be accessed in various ways from a modern Linux desktop, but if you want everything (such as rsync) to work (most) all of the time, it's best to just mount the Windows share to a local mountpoint. Then, regardless of the type of access you desire, you just access the filesystem as if you were browsing local files.
Line 79: Line 96:
 </file> </file>
  
 +===== Script =====
 +
 +:!: Script must run as root.
 +
 +:!: Limit visibility as the script contains passwords (not secure).
 +
 +<file>
 +sudo chown root.root /home/username/bin/mymounts
 +
 +sudo chmod 4700 /home/username/bin/mymounts
 +</file>
 +
 +
 +<file>
 +#!/bin/bash
 +# ~/bin/mymounts
 +# Make sure package cifs-utils is installed
 +# Store this file in your home directory with 4700 perms as it needs to run suid and contains SMB password
 +
 +# Set variables here:
 +SMBSERVER=<SMB Server Name>
 +SHARENAME1=<SMB Share Name>
 +SHARENAME2=<another SMB Share Name>
 +SMBUSER=<SMB User Name>
 +SMBPASS=<SMB Password (escape BASH symbols)>
 +SMBDOM=<SMB Domain Name>
 +USERNAME=<Linux User Name>
 +USERGROUP=<Linux User Group>
 +# End of variables
 +
 +mkdir -p /mnt/$SHARENAME1
 +mkdir -p /mnt/$SHARENAME2
 +
 +#These older commands did not need to be run as root
 +#smbumount ~/mnt/$SHARENAME1
 +#smbmount //$SMBSERVER/$SHARENAME1 ~/mnt/$SHARENAME1 -o username=,password=
 +#smbumount ~/mnt/$SHARENAME2
 +#smbmount //$SMBSERVER/$SHARENAME2 ~/mnt/$SHARENAME2 -o username=$SMBUSER,password=$SMBPASS
 +
 +umount /mnt/$SHARENAME1
 +mount -t cifs //$SMBSERVER/$SHARENAME1 /mnt/$SHARENAME1 -o rw,_netdev,username=$SMBUSER,password=$SMBPASS,domain=$SMBDOM,uid=$USERNAME,gid=$USERGROUP,iocharset=utf8,file_mode=0777,dir_mode=0777
 +umount /mnt/$SHARENAME2
 +mount -t cifs //$SMBSERVER/$SHARENAME2 /mnt/$SHARENAME2 -o rw,_netdev,username=$SMBUSER,password=$SMBPASS,domain=$SMBDOM,uid=$USERNAME,gid=$USERGROUP,iocharset=utf8,file_mode=0777,dir_mode=0777
 +
 +</file>
networking/linux/linux_smb.1390669967.txt.gz · Last modified: 2014/01/25 10:12 by gcooper