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

Both sides previous revision Previous revision
Next revision
Previous revision
networking:linux:linux_smb [2014/01/25 10:30]
gcooper
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 ======
- 
-FIXME This doesn't work on newer Ubuntu distros. 
  
 ===== Newer Distros ===== ===== Newer Distros =====
Line 7: Line 5:
 <file> <file>
 sudo apt-get install cifs-utils sudo apt-get install cifs-utils
-sudo mkdir /mnt/sharename 
-sudo mount -t cifs //server/sharename /mnt/sharename -o rw,username=<username>,password=<password> 
 </file> </file>
- 
-If mane resolution fails, try the IP address of the server: 
  
 <file> <file>
-sudo mount -t cifs //192.168.0.100samba/ -o rw+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> </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 ===== ===== Older Distros =====
Line 97: 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.1390671015.txt.gz · Last modified: 2014/01/25 10:30 by gcooper