Samba - mounting share from linux

From thelinuxwiki
Revision as of 15:50, 26 March 2024 by Nighthawk (Talk | contribs)

Jump to: navigation, search

Contents

required packages

on gentoo... look for something similar in your distro's repo

net-fs/cifs-utils
dev-perl/Filesys-SmbClient

Listing samba / cifs shares

# smbclient -L xpmachine
Enter root's password: 
Domain=[xpmachine] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]
       
Sharename Type Comment --------- ---- ------- E$ Disk Default share IPC$ IPC Remote IPC cdrom Disk data Disk ADMIN$ Disk Remote Admin C$ Disk Default share Domain=[xpmachine] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager] Server Comment --------- ------- Workgroup Master --------- -------


Mount command syntax

newer mount command (smbfs depricated)

mount -t cifs //server/E$ /mnt/test -o username=jsmith/mydomain,password=hackth1s

required package for cifs file type on debian: cifs-utils

sudo apt-get install cifs-utils

This might require the mount-cifs package

Allowing user right permissions

if you don't specify uid and gid in mount command and mount as root, write attempts for regular users will get "permission denied".

example:

suppose I mounted a samba drive on 192.168.0.10 as root (including using sudo). When I check how it was mounted with the "mount" command I can see the uid and gid parmeters are 0 for root.

$ mount | grep 192.168.0.10
//192.168.0.10/upload on /home/jsmith/samba type cifs (rw,relatime,vers=default,cache=strict,username=jsmith,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.0.10,file_mode=0755,dir_mode=0755,soft,nounix,serverino,mapposix,rsize=1048576,wsize=1048576,echo_interval=60,actimeo=1)

solution:

when running the mount command, set uid and/or gid to include the user(s) of interest

example:

sudo mount -t cifs //192.168.0.10/upload /home/jsmith/samba -o rw,username=jsmith,uid=1000,gid=1000

where the uid/gid match the user as seen in the passwd file

$ cat /etc/passwd | grep jsmith
$ mount | grep 192.168.0.10

//192.168.0.10/upload on /home/jsmith/samba type cifs (rw,relatime,vers=default,cache=strict,username=jsmith,uid=1000,forceuid,gid=1000,forcegid,addr=192.168.0.10,file_mode=0755,dir_mode=0755,soft,nounix,serverino,mapposix,rsize=1048576,wsize=1048576,echo_interval=60,actimeo=1)

jsmith:x:1000:1000:jsmith,,,:/home/jsmith:/bin/bash

old mount command

mount -t smbfs //servername/sharename /mountdirectory -o username=mywindowsusername,password=mywindowspassword


samba users

/etc/samba/smb.conf Uncomment the security line *** this will require a local user account for each smbuser ***

security = user
username map = /etc/samba/smbusers

make local user account, no hoee dir or local passwd needs to be set

useradd smbuser

add user to /etc/samba/smbusers

<localusername> = “<samba username>”.

example

smbuser = smbuser