Samba share your VPS drive

The easiest way, not saying it is the best, to copy files in windows is by using  Windows Explorer. You can mount your VPS disk in Windows using the SMB/CIFS protocol, in this guide I will demonstrate this by installing Samba on a VPS and then mount that directory on my Windows machine.

I will create a specific user that will not be able to login via SSH and the Samba share will be to that users home directory, there should be no access outside of this directory.

Installation

The installation begins with the following command:

After the command is executed and the packages are successfully installed, let’s update the configuration.

First a copy of the configuration file as backup:

Then let’s open the config file with nano so we can edit the configuration:

The following configuration allows authentication of added Samba  users and give them access to save data in the user’s home directory. That is, each user added can access the server via Samba/SMB/CIFS and access the files in their home directory.

Save the config file and exit nano.

Then we restart the Samba server to load the updated configuration:

Create users and add to Samba

As a security measure we do not allow the samba users to login to the system, this way if a username/password combination gets out, only the files in that shared directory is accessible, not the rest of the VPS.

In this example, the username will be shrfldusr (short for “shared folder user”):

Follow the on screen instructions and enter the information about the account you are creating.

When the user has been created, we add the user to the Samba database and assign a password. Make sure that the password set is not something that is easily guessed.

This is the command which is used to add the user shrfldusr to the Samba database and enable access to the shared folder.

If you get this error message in return when trying to set the password:

This means that the user account is not found and the adduser command above failed. Go back and add the user again, watch for error messages.

Short note on some Samba commands that is good to know about

Some/all options are only available when running smbpasswd as root, so to make sure they are working, execute as root.

Add and activate user accounts (there must be a system user with that username)

This option specifies that the username following should be deleted from the local smbpasswd file.

This option specifies that the username following should be disabled in the local smbpasswd file

This option specifies that the username following should be enabled in the local smbpasswd file, if the account was previously disabled.

 

Time to get back to the guide and the last part, adding the Samba folder in Windows.

Map Network drive in Windows:

Press the WINDOWS + E keys on your keyboard to open Windows Explorer.

 Images shown here are from a Windows Server 2012 installation

explorerClick on the Computer menu and then on the Map Network Drive icon to open the Map Network Drive Dialog.

 

 

 

 

map_network_drive

Select the Drive letter that you would like it to have on your local desktop and enter the network path in the Folder box.

Make sure you tick the Connect using different credentials box.

When clicking on the Finish button you will be presented with a login dialog where you enter the username and password that you used above.

 

So … by now you your network hard drive is successfully installed, configured and integrated into Windows.

If you can’t connect to your samba share, make sure you check other applications as your firewall and/or services that are disabled that is needed.

1 comment for “Samba share your VPS drive

  1. Patrick
    March 30, 2015 at 05:49

    Thank you for this, this guide really helped me use a VPS that was just sitting.

Leave a Reply

Your email address will not be published. Required fields are marked *