Samba Server: Moodle Prod Server –
Samba Client: Moodle Dev Server –

In our scenario, we want to transfer files from dev to prod

Samba Server

1- open moodle prod server and install samba server

$ ssh -l msen
$ sudo apt-get update
$ sudo apt-get install samba

2- set samba password for machine user msen

$ sudo smbpasswd -a msen

Samba passwords are stored in /etc/samba/smbpasswd

3- Create a directory called moodle to be shared

$ sudo mkdir /home/msen/moodle
$ sudo chmod -R 777 /home/msen/moodle

4- Make a safe backup copy of the original smb.conf file to your home folder, in case you make an error

$ sudo cp /etc/samba/smb.conf ~

5- Edit the smb.conf file

$ sudo nano /etc/samba/smb.conf

Once “smb.conf” has loaded, add this to the very end of the file

 path = /home/msen/moodle
 available = yes
 valid users = msen
 read only = no
 browseable = yes
 public = yes
 writable = yes

6- Restart the samba

$ sudo service smbd restart

7- Once Samba has restarted, use this command to check your smb.conf for any syntax errors

$ testparm


Samba Client

1- Open moodle dev server and install samba client

$ ssh -l msen
$ sudo apt-get install smbclient

2- make sure the samba 139 and 445 ports of samba work

$ sudo iptables -S

if not there,

$ sudo iptables -L –line-numbers

delete the drop line

$ sudo iptables -D INPUT 6
$ sudo iptables -A INPUT -p tcp –dport 139 -j ACCEPT
$ sudo iptables -A INPUT -p tcp –dport 445 -j ACCEPT

now add back the drop line

$ sudo iptables -A INPUT -j DROP

3- List all shares

$ smbclient -L // -U msen

 Enter msen's password:
 Domain=[WORKGROUP] OS=[Unix] Server=[Samba 4.1.11-Ubuntu]
 Sharename Type Comment
 --------- ---- -------
 IPC$ IPC IPC Service (online server (Samba, Ubuntu))
 moodle Disk
 print$ Disk Printer Drivers
 Domain=[WORKGROUP] OS=[Unix] Server=[Samba 4.1.11-Ubuntu]
 Server Comment
 --------- -------
 ONLINE online server (Samba, Ubuntu)
 Workgroup Master
 --------- -------

4- Let’s transfer moodle files. Make sure you are under the /opt/moodle/

Go to under client’s directory where you want to transfer your files from

$ cd /opt/moodle

Connect Samba

$ smbclient // -U msen
smb: \> recurse
smb: \> prompt
smb: \> mput *

mput *  puts all the files from client’s /opt/moodle directory into server’s /home/msen/moodle directory 
 By default recurse option is OFF. Entering recurse command on the smb prompt will toggle this option to ON, and similarly prompt option is ON by default. Entering prompt option will toggle this option to OFF, so that smbclient will not ask confirmation for each file in the subdirectories. mput will put multiple files matching trunk* pattern on the local filesystem.

Other Samba Commands


To exit Ctr+C

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s