Samba
Samba is a suite of utilities that allows your Linux box to share files and other resources, such as printers, with Windows boxes.
Edit the /etc/samba/smb.conf as follows
cat smb.conf
[global]
workgroup = WORKGROUP netbios name = Ubuntu server string = %h server (Samba, Ubuntu) dns proxy = no log file = /var/log/samba/log.%m max log size = 1000 syslog = 0 panic action = /usr/share/samba/panic-action %d encrypt passwords = true passdb backend = tdbsam security = user username map = /etc/samba/smbusers obey pam restrictions = yes invalid users = root passwd program = /usr/bin/passwd %u passwd chat = *Enter\snew\sUNIX\spassword:* %n\n *Retype\snew\sUNIX\spassword:* %n\n *password\supdated\ssuccessfully* . socket options = TCP_NODELAY [sharedata] comment = Test share directory = /stage read only = no hide unreadable = yes # settings for recycle bin vfs objects = recycle recycle:repository = /stage/shared-recycle/ recycle:noversions =2 [secretdata] directory = /stage/data browseable = no valid users = user1, user4 read list = user4 readonly = no
Create the samba user and password
# smbpasswd -a user1
Create /etc/samba/smbusers file and map samba users to UNIX users. The format is <Linux_User_Name> = “<samba username>”. You can use a different samba user name to map to an Linux account.
# vi /etc/samba/smbusers user1 = user1 user2 user3 user4 = user4
Restart the samba daemon
If tdbsam backend is used for password, to list and view the encrypted password of SAMBA users
# pdbedit -w -L
Swat
SWAT, Samba's web based configuration tool enables you configure your smb.conf file without you needing to remember all the formatting. Each SWAT screen is actually a form that covers a separate section of the smb.conf file into which you fill in the desired parameters. For ease of use, each parameter box has its own online help. SWAT immediately changes the functioning of Samba whenever you commit your changes through the web GUI.
The enabling and disabling, starting and stopping of SWAT is controlled by xinetd, via a configuration file named /etc/xinetd.d/swat. Here is a sample:
service swat
{
port = 901
socket_type = stream
protocol = tcp
wait = no
user = root
server = /usr/sbin/swat
log_on_failure += USERID
disable = no
only_from = localhost
}
The default configuration only allows SWAT web access from the console of Samba server as user root on port 901. This means you'll have to enter "http://127.0.0.1:901" in your browser to get the login screen.
You can make SWAT accessible from other servers by adding IP address entries to the only_from parameter of the SWAT configuration file. Here's an example of an entry to allow connections only from 192.168.1.3 and localhost. Notice that there are no commas between the entries.
only_from = localhost 192.168.1.3
Samba Client tasks
To list all the shared directoris in a system called test1
# smbclient -L [system name|iPaddress] --user <user_name>
To mount a shared windows directory share1 to local unix system
# mount -t smbfs -o username=<user_name>,password=<Passwd>,uid=<local_user_name>,
gid=<local_gid> //windows-system_name/share1
or
# mount -t cifs -o username=<username>,password=<passwd>,domain=<domainname>,
uid=<local_user_name>,gid=<local_gid> //windows-system_name/share_name
To automatically mount a windows share on a linux system, add the following line to the /etc/fstab file
//<IPaddress>/share_name <mount_point> cifs \ username=<uname>,password=<passwd>,uid=500,gid=500,file_mode=0644,dir_mode=0755 1 2
To keep the user name and password in a separate file instead of giving it on /etc/fstab file
//<IPaddress>/share_name <mount_point> cifs \ credentials=<file_name>,uid=<uid_number>,gid=<gid_number>,file_mode=0644,dir_mode=0755 1 2 //192.168.123.25/data /pcdata cifs credentials=/data \ /etc/cifs.secret,uid=500,gid=500,file_mode=0640,dir_mode=0750 1 2 # cat file_name username=test1 password=testpasswd uid=500 gid=500