Please support VectorLinux!

Author Topic: HOWTO: Share files with Windows computers, using command line.  (Read 12339 times)


  • Administrator
  • Vectorian
  • *****
  • Posts: 4072
How to share files with Windows computers, using command line. Tested on VL 5.1 Std.

Linux can communicate with Windows using "smb" (samba). It is included with recent versions of VL and may be installed during initial setup or added later. The package has two components, a client and a server. The client is used to read network shares on other computers and generally requires little effort to use. The server is for offering shares for others to read, and requires more configuration to get working.

The software firewall must either be disabled or configured to allow the operations.

Entries in bold are variables where you insert the appropriate information.
Lines in italic are commands for you to type, followed by "Enter".

Become root.
Make sure samba is installed:
slapt-get --show samba
If not, install it:
slapt-get --install samba
Set permissions to allow smb mounting by users:
chmod +s /usr/bin/smbmnt   
 (note it is "smbmnt", not "smbmount", which we will use later)

EDIT: Newer versions of Samba do not allow this. The following mounting procedure will only work as user root.

To connect to windows computers with shared folders:

As a regular user, scan your network:
You will be asked for your password. The client will supply your user name and password to the remote machines. If you are connecting to a WXP machine with "Simple file sharing" enabled, the password is irrelvant. Otherwise, your username/password will need to be authorized for access by the remote server.
The result returned should be something like:
           \\WINMACHINE-1                                   MyComputer
                          \\WINMACHINE-1\SHARED             Shared Files
                          \\WINMACHINE-1\IPC$               Remote IPC
                          \\WINMACHINE-1\M$                 Default share
                          \\WINMACHINE-1\ADMIN$             Remote Admin

.. etc ..

The shares ending in $ can be ignored.
Now to connect to SHARED on WINMACHINE-1 in WORKGROUP:
mkdir /path/dir
/usr/bin/smbmount //winmachine-1/shared /path/dir
You will be asked for password.
If all goes well, you will now have access to the remote share, mounted on "/path/dir"

You can also connect as a different user like this:
/usr/bin/smbmount //winmachine-1/shared /path/dir -o username=user_name

Using the samba server to offer shares for other machines to read:

Become root.
Enable samba as a service on boot:
  continue to > service > srvset > (your runlevel, or all) > (Check the box for samba)

To start out easy, try one universally readable/writeable without authentication.
This is like WXP using "simple file sharing" and "allow users to change files":

Prepare the share. Normal Linux file restrictions apply, as well as samba restrictions.
mkdir /path/smb_shared
chmod 777 /path/smb_shared

Edit /etc/samba/smb.conf:
Find the following line and change WORKGROUP to reflect your workgroup name:
workgroup = WORKGROUP
Next line to change determines access control. "share" is easiest to use, but less secure than "user".
security = share
At the end of the file, add this to define the share:
   comment = Read-write for all
   path = /path/smb_shared
   read only = no
   public = yes
   browseable = yes
   guest ok = yes
   writable = yes
   create mask = 0666
   directory mask = 0777

Restart samba:
/etc/rc.d/init.d/samba restart
Now try connecting from an external machine.


A more secure example, accessible for an authenticated user:

Create your network user and assign password:
adduser smb_user_name
  (it will walk you through the steps)
smbpasswd -a smb_user_name
You can also just use the smbpasswd command for an existing user account.

Prepare the share:
mkdir /path/smb_shared
chown smb_user_name /path/smb_shared

Edit /etc/samba/smb.conf:
Change the following line to reflect your workgroup name:
workgroup = WORKGROUP
Enable the higher security level:
security = user
Define the share:
   comment = Authenticated access
   path = /path/smb_shared
   public = no
   browseable = yes
   read only = no
   writable = yes
   create mask = 0666
   directory mask = 0777


The samba server has a lot of options for you to play with, hopefully this will get you started.
« Last Edit: January 09, 2011, 09:20:17 pm by nightflier »