Tag Archives: Samba

Samba and Linux Mint

In my original post on Samba I covered a lot of basics. Recently I learned a bit more using Linux Mint. In Mint Samba is already loaded in the process of installing the OS. I remembered that I had to add all the computers to the same workgroup to get Linux and Windows to play together. But I couldn’t get two Mint machines to work via Samba. Name resolution was the issue.

I kept getting a “Failed to Retrieve Share List from Server” error. I was able to move files from a Mint machine to the Windows machine and then to the other Mint machine. The only thing I had to do is open up permissions on the folder to let Samba write to it. I used the Public folder under the /home/user directory. I would think that adding Samba to my user group would also work, I have checked into this and this is the answer I find…

http://unix.stackexchange.com/questions/206309/how-to-create-a-samba-share-that-is-writable-from-windows-without-777-permission

 

I did install Winbind thinking that it might help out. Windows machine can see Public folder, go into it and read and write with 777 permissions on it.

winbind is a component of the Samba suite of programs that solves the unified logon problem. Winbind uses a UNIX implementation of Microsoft RPC calls, Pluggable Authentication Modules (PAMs), and the name service switch (NSS) to allow Windows NT domain users to appear and operate as UNIX users on a UNIX machine.

https://www.samba.org/samba/docs/man/Samba-HOWTO-Collection/winbind.html

 

I started with this post which got me sort of there…

Samba Basic – Lesson 1: Samba Simply

https://community.linuxmint.com/tutorial/view/672

 

Name Resolution with Samba

http://www.oreilly.com/openbook/samba/book/ch07_03.html

How to Fix ‘Failed to Retrieve Share List from Server’ in Ubuntu 12.04 / 11.10 when File Sharing with Windows

How to Fix ‘Failed to Retrieve Share List from Server’ in Ubuntu 12.04 / 11.10 when File Sharing with Windows

 

Backing up Windows User’s to Folders to a Linux File Server

Robust File Copy for Windows

robocopy.exe available as part of rktools <-download page, can be used to copy files across the network to a Linux machine into a folder setup using Samba.

The DOS batch file below is called serverbackup.bat on my machine. It can start the Linux server using wolcmd <-download page, from Depicus.com and will copy a users folder to a folder on the server and creates a log file C:\tools\backup.log, then it shuts down the Windows PC with a 120 second delay. This delay is mostly there for testing. If the robocopy command goes belly up, the PC will try to jump right to the shutdown, which makes troubleshooting difficult. So leaving a delay is helpful as one can abort a shutdown by executing…

shutdown /a

…from the command line in Windows to stop the machine from shutting down.

I had to review how robocopy worked before deploying it in a backup script and I found an exact example of what I was looking for on Jacob Surland’s photography blog Caught in Pixels. I reviewed his post How to create a backup script using Robocopy before writing the serverbackup.bat script. I have the script downloadable here named serverbackup.bat, rename and modify as needed.

REM Wake Server, if it is already on, no harm done. It takes about 17 secs for server to start so REM robocopy will get an error and should keep retrying
REM run Depicus Wake on Lan from Command Line. Validated, Works!
 wolcmd yourmacaddr localserveripaddr 0.0.0.0 9
REM Copy User folder to \files\user on server via Samba links
 REM /MIR = purge files from dest. that do not exists in source
 REM /M Copy Archiveable files & reset attribute - not using this yet!!!
 REM /XA:SH exclude system and hidden important for user space
 REM /FFT fixes timing up for LINUX assumes FAT file times ( 2 sec granularity)
robocopy "C:\Documents and Settings\Erick_2" \\UBUNTUSERVER\Erick_Backup /MIR /XA:SH /XJ /FFT /W:1 /R:5 /LOG:C:\tools\backup.log
REM Shutdown PC when backups are done
shutdown -s -f -t 120

So far it works….

Resources

Windows Server 2003 Resource Kit Tools aka rktools

Depicus wolcmd download page

How to create a backup script using Robocopy

 

Samba on a Linux Server

Samba

Backup /etc/samba/smb.conf  before toying with it! Copy it somethings like /etc/samba/smb.bak or /etc/samba/smb.orig for the original and bak for files that you are modding along the way to getting this working. I admit Samba was a bit of a pain to get working, I fussed around a bit on the server and the Windows machines until success occurred.

One mistake I made was to name the folders by the paths as they appear on the server. Bad idea, Microsoft Windows did not like forward slashes and denied access to the folders. Using slashes and perhaps other non-alphanumeric characters are a no-no in the server folder names.

Make Folders on the Server

I created folders named /files/public and /files/erick on the server. More can be added for additional users. What I am doing with the folders is backing up user profiles from Windows machines in the /files/user folders. The public folder is going to hold things like install files for the Windows machines, anti-malware & etc tools, C compiler and DOS DOS-UNIX equivalent tools and so on.

I executed the following commands on the server…

sudo mkdir /files
cd /files
sudo mkdir public
sudo chmod 777 public
mkdir erick

I believe I did a chmod to 777 on files as well. I made the erick directory with my own credentials, I am owner. Directory is created as a 775 by default…

rwxrwxr-x 2 erick erick 4096 Dec 10 21:12 erick

Later on I created a renee folder. Same drill, I did an su and logged in as the user renee after I created the account and ran a mkdir renee under files.

You need to create a Samba password for yourself and any users. Make it the same as the password that you log into the Win machines, especially important if you want to access home folders.

The command for adding a Samba user and password is…

smbpasswd -a user
Linux Users

While on the users topic adding a Linux user with a home directory is accomplished with the following command…

sudo useradd -d /home/username -m username

Adding the password, don’t skip this, if you forget to do this it will cause problems down the road and it might take a while to figure the problems out.

sudo passwd username

There is a command that can take the contents of the skel directory /etc/skel,  into a users home directory. This sets up the files and folders. Normally this will happen when you use the -d /home/username option on useradd. But if you create a user without a home directory and add one later the following command may be helpful…

mkhomedir_helper username

I followed the method above to add a user renee and then created a /files/renee directory on the server.

Editing the smb.conf file

For the following, I opened my /etc/samba/smb.orig and etc/samba/smb.conf files in the eMacs editor and differenced them. The gray lines and sections show the changes, I have highlighted them with red rounded rectangles for clarity. The biggest change is at the bottom of the file where I added code to allow access to the /files/public, /files/erick and /files/renee directories.

Global Settings Changes in smb.conf
Changes under Global Settings in smb.conf
Changes under Global Settings in smb.conf
Authentication Section changes in smb.conf
Changes under Authentication in smb.conf
Changes under Authentication in smb.conf
Share Definitions sections changes in smb.conf.

This is optional and will allow the home directories of the users to be made accessible with read/write access on the network. In this section the changes are post the most part the uncommenting of the grayed out lines that you see below. I think the only change beyond that was setting read only = no.

Share Definitions sections changes in smb.conf
Share Definitions sections changes in smb.conf
Section added to tail of smb.conf for user defined directories

Follow this example to add your own directories to be accessible from the Windows network.

Don’t use any slashes in the names in the [brackets]. I imagine a lot of non-alphanumeric characters will make this fail. Slashes were my problem. I was trying to be clever and using things like [/files/erick]. Also I went to using an underscore instead of a space in the names. This makes it work better from the Windows CLI and scripts, space does not always translate well. I have had issues with scripts where it takes the first part of the folder name and thinks the 2nd part is a switch to the command or something, resulting in failure. Basically the DOS like Windows CLI (Command Line Interface) environment does not like spaces!

I have not tried setting browsable to no. I imagine it can be only access by knowing the names of the files and probably by navigating using the CLI from Windows. This would be acceptable for the two named directories as they are only backup directories and I don’t imagine I would have to browse to the often.

 

Section added to tail of smb.conf for user defined directories
Section added to tail of smb.conf for user defined directories
Restart

Samba needs to be restarted any time you change the smb.conf file. Use the command….

sudo service smbd restart

…to restart.

Windows Machine

The Windows machine needs to be set to the same workgroup. It is best to have the same user names and passwords to both the Win users and the Samba users, in this manner all will work including home file sharing. When you make changes, sometimes you have to log out and in to the Windows user for them to take effect or else you get errors like the folder is not accessible, and other like it about permissions. Windows will prompt for a username and password to access folders as well, especially if the users and passwords do not match between Windows and the Samba server.

smbclient command

Running smbclient -L servername from the server is a good sanity check that the shares are showing up and that the server actually sees the Windows network. If this looks good generally you are in business with Samba at least from the server side.

erick@ubuntuserver:/etc/samba$ smbclient -L ubuntuserver
Enter erick's password:
Domain=[MSHOME] OS=[Unix] Server=[Samba 3.6.3]

        Sharename       Type      Comment
        ---------       ----      -------
        homes           Disk      Home Directories
        print$          Disk      Printer Drivers
        Erick_Backup    Disk      Erick's Files at /files/erick
        Renee_Backup    Disk      Renee's Files at /files/renee
        Public          Disk      Public Files at /files/public
        IPC$            IPC       IPC Service (ubuntuserver server (Samba, Ubuntu))
        erick           Disk      Home Directories
Domain=[MSHOME] OS=[Unix] Server=[Samba 3.6.3]

        Server               Comment
        ---------            -------
        RENEECOMPUTER        Renee's Computer
        UBUNTUSERVER         ubuntuserver server (Samba, Ubuntu)

        Workgroup            Master
        ---------            -------
        MSHOME               RENEECOMPUTER



smbstatus command

Executing smbstatus from the server command line can tell you what computers are connected and if any files are locked. Try executing it while file operations are in progress to see how it behaves. After seeing it in operation, what is going on becomes obvious for the most part. Without any computers connected to Samba folders, nothing interesting is reported. This means that this tool be helpful troubleshooting Samba if you can’t even connect to the folders. But may be of use to troubleshoot issues when all is working OK and then an issue arises. I also have a script that runs and allows the server to shut down when idle, it executes smbstatus as a test to see if any computers are using Samba so the server won’t shutdown while Samba is in use.

It has command line options which I haven’t explored much myself yet.

For the man page on smbstatus

https://www.samba.org/samba/docs/man/manpages/smbstatus.1.html

 

The next topic in this series is…
Installing OwnCloud rounds out the server
Additional

 

There is a good YouTube tutorial online that runs through the basics of setting Samba up on Ubuntu Server 12.04. It worked for me.

Ubuntu Server Installation and Initial Config Guideline

This is meant to be an outline not a complete guideline. It is based off on notes I took and may be helpful to keep me or someone else straight on the process in the future. There are some sections that are a bit light, but there is more out there on the web and half the problem for me at least is remembering this kind of outline. If I have the outline, I can jump off and find more. This particular post on the install is rather long, but it didn’t seem like a good idea to break it up.

Install,  using Ubuntu Server 12.04

Boot via the DVD that was created by burning the downloaded ISO to it.

Ubuntu Server 12.04 Screen
Ubuntu Server 12.04 Screen

Select Install Ubuntu Server, unless of course you want to test out RAM, a good idea if it has been freshly installed. Which was true in my case. So I ran MEMTEST overnight via this menu first.

Next you will be presented with screens to select language, location and keyboard type.
Ubuntu Server Select Language Screen
Ubuntu Server Select Language Screen
Ubuntu Server Select Location Screen
Ubuntu Server Select Location Screen

If you know what kind of keyboard you have select no to the next screen. If not selecting yes will put the keyboard through a test, having you press various keys to identify it.

Ubuntu Server Detect Keyboard Screen
Ubuntu Server Detect Keyboard Screen

 

Ubuntu Server, Select The Keyboard Screen
Ubuntu Server, Select The Keyboard Screen
Ubuntu Server Select Keyboard Layout Screen
Ubuntu Server Select Keyboard Layout Screen
Next the Ubuntu Server install will start loading additional components, this can take a few minutes…
Ubuntu Server Install, Installing Additional Components
Ubuntu Server Install, Installing Additional Components
 Networking Setup

Ubuntu Server will automatically configure DHCP. Later on, after the install, this will be switched to a static IP address.

Ubuntu Server Auto configuring with DHCP
Ubuntu Server Auto configuring with DHCP

Create a hostname for the computer. Choose something that makes sense for you. A really long hostname ( I think > 14 chars) can present issues with Windows when using Samba. It will truncate the name, just something to be aware of.

Ubuntu Server, Configure the Network, Create a Hostname
Ubuntu Server, Configure the Network, Create a Hostname
User and Password

You can set up a user next by filling out a username and password. After the installation you can add more users if you need to.

The first screen will ask for your name, this could be your real name.

Ubuntu Server Setup Users and Passwords Screen
Ubuntu Server Setup Users and Passwords Screen

Next you will enter your username. Something simple like your first name in all caps is a good choice.

Ubuntu Server Enter a Username Screen
Ubuntu Server Enter a Username Screen

Choose a decent password. Something not listed in a dictionary is a good choice, with some numbers and a capitalized letter, punctuation as well. One approach taken is to take two unrelated words that are easy to remember and concatenating them. Whatever you do, don’t lose it, I am not sure you can recover it unless you can reset it as root, provided you have that password.  In Ubuntu, you have to log in as a user to even execute sudo. So if you have one user and lose the password, it’s probably game over.

Ubuntu Server Choosing a Password
Ubuntu Server Choosing a Password

To encrypt or not to encrypt your home directory on your Ubuntu Server install. I chose no, it’s a server, I am not going to do much with the home directory. Encryption is nice, but it comes with a small speed cost of decoding, this could be a burden on a slow processor.

Ubuntu Server Encrypt Home Directory Question
Ubuntu Server Encrypt Home Directory Question
Time Zone

Where are you in the world?  I think the install is taking an educated guess as to where you are, so what it chooses may be correct, just double check. If not, set up your time zone via this drop down menu. After the install it is possible to install ntp which can keep the server clock sync’ed up with an atomic clock time.

Ubuntu Server, Check The Time Zone
Ubuntu Server, Check The Time Zone
Partitioning

Whole disk, LVM. Lots of options. I choose to wipe the disk clean and use LVM. I will be adding disks to this machine and with LVM, they can appear as one big disk, not mounting required. LVM is a thin layer of software that manages the Logical Volumes. Therefor it does consume a small amount of resources and must lower disk transfers slightly. One thing that I did noticed once with an LVM disk, is that I could not read it using a IDE to USB adapter. It was invisible to it. I have to try plugging that disk into a Linux machine at some point to see if I can read it’s contents. So it seems that LVM could complicate a recovery of a disk. Supposedly an advantage of LVM is that you can mirror copy the volumes and expand them across disk. I need to research this some more as it is new to me.

Ubuntu Server Guided Partitioning Using Entire Disk and LVM
Ubuntu Server Guided Partitioning Using Entire Disk and LVM

If you have more than one disk, you have to choose which one the OS will install to.

Ubuntu Server, Choose a Disk to Partition
Ubuntu Server, Choose a Disk to Partition

At this point in the install, I ran into an issue with the fact that the disk I was trying to use was originally used in another Linux machine with 3 disks used in LVM. Nothing I did seemed to work as it gave me a warning about the disk being a part of a 3 disk LVM set. I stopped the install and used a CD that came with a drive I bought years ago and wiped out the drive. Then I did the reinstall and successfully made it to the following confirmation screen. If all looks well you can hit Yes, if not hitting No will allow you to work backwards. Hitting Yes is final as disk writes will occur.

Ubuntu Server, Partitioning Disks, Confirmation Screen
Ubuntu Server, Partitioning Disks, Confirmation Screen
System Install, Configuring Updates and Installing Software

Once the partition in complete the OS will install, which will take several minutes.

Ubuntu Server Installing Base System
Ubuntu Server Installing Base System

There is an option to have automatic updates, this is a good idea, especially for a headless server. So it can take care of itself with a minimum of fuss.

Ubuntu Server, Configure tasksel for Automatic Updates
Ubuntu Server, Configure tasksel for Automatic Updates

Choose software to install. Open SSH is a must if you are to remotely shell into the server. Because I will be running OwnCloud on this unit and it uses a web interface and a database and PHP, installing LAMP Server is a must. I will also make a few folders that can be reached directly from Windows computers on the network, mostly for direct backups, so Samba file server is a must.

Ubuntu Server Software Selection
Ubuntu Server Software Selection

 

Final Steps for Ubuntu Server 12.04 install

The Ubuntu server install will prompt for installation of software. Install the following when prompted by the screen.

  • Open SSH
  • LAMP
  • Samba Server
 MySql Password

Because the LAMP Server (Linux-Apache-MySql-PHP)  installs MySql a password is needed for the “root” user of the database. During the process of configuring LAMP, a prompt will appear for a MySQL root password, make it something memorable in case you ever have to manage or do work with the database manually, or if a program asks for it, such as when doing a WordPress install.

LAMP Install Choosing a MySql Password
LAMP Install Choosing a MySql Password
GRUB

As the description for GRUB states this is the only install going in, so it safe to hit Yes and go ahead. Results may vary for you specific case. If you have a multi boot machine, GRUB will setup Ubuntu Server to load first, if you are configuring a multi boot machine.

Ubuntu Server GRUB Install
Ubuntu Server GRUB Install

The done screen, pull out the disk hit continue and the PC now will reboot, I went into the BIOS and did a few more things to it.

Ubuntu Server Installation Finished
Ubuntu Server Installation Finished
Additional  Steps in the BIOS

All BIOS are a bit different. Yours may not look the same, but should have similar settings. This is a Dell Dimension 2400. Configure the BIOS to ignore keyboard errors “Do Not Report”, important for unattended operation with a keyboard and monitor!

Setting BIOS to Ignore Keyboard Errors
Setting BIOS to Ignore Keyboard Errors

I also set “Remote Wake Up” to On as I will use Wake On LAN to wake this machine up remotely. I cover it here … Wake On LAN via Ubuntu Linux

Remote Wake Up Help Screen Description
Remote Wake Up Help Screen Description

I will set Suspend Mode to S3. This has worked well for me with Dell machines in the past. I am considering writing a CRON script that will suspend to RAM when the server is idle for a period of time, so setting this to what I want it to be now is a good idea.

Setting Suspend Mode to S3
Setting Suspend Mode to S3

If the power goes out and comes back on I want the server to go back to what ever state it was in, if off stay off, if it was on, restart. I have used this in the past and it does work well.

Setting AC Power Recovery to Last
Setting AC Power Recovery to Last
Final Steps for Install when the machine reboots

When you exit the BIOS, you be prompted for your username and password.

For good measure run the update and upgrade commands, if all is well they should complete without error.

sudo apt-get update
sudo apt-get upgrade
One of the first steps when configuring a server post-install is to set up a static IP address.

This is explained in the next post…

Configure Static IP and installing NTP

More Resources…

How to Make an Ubuntu File Server With Samba

on Youtube.

Plus … Find a decent Guide to Install Ubuntu Server here

 

 

 

The old server

I had an old NEC P3-500 computer from 2000 set up as a server. It ran Lubuntu 13.10. SSH, vsFTP, LAMP stack, Webmin, Samba, code for remote desktopping and a WordPress install.

I used it to test out things, I learned a lot about WordPress in a short span of time on it. Plus I had it running two web cams and placing time lapse frames on line. I was using the cams to monitor indoor temperatures when I was away from home in the winter. It was a good test bed, but quit in late March. No video, no booting, I decided not to troubleshoot, it was old and worked long enough. It still had the original 8gb HD, which started with Win98 then XP, the Ubuntu 9.10, then Lubuntu, good life span for a drive.

NEC Server
NEC Server on top of workstation

A few months ago I came across a Dell Dimension 2400 at no cost. Higher performance than the NEC. So I will go with that as the replacement. The idea is to load Ubuntu Server on it, no need for a desktop, I realized. I am comfortable enough with the Linux command line, been using it since 1997, to go without a “desktop”. In the meantime since the last server, I discovered ownCloud 

OwnCloud

OwnCloud will let me set up a personal cloud, limited only by hard-drive space. I have not used it much yet, but it would be good for storage of photos and music, plus contacts, bookmark and calendar sync. It seems promising. I am reading the user manual and administrator manual. Two of the features that I am interested in are, making a photo gallery in it and being able to store music files and streaming them. Then I could have my personal “internet radio” station and listen to the music that I want to on any device, in theory, anywhere.

Samba

I finally got Samba working, which allows the Linux computer to interface correctly with Windows as far as file sharing. Now I can create a network folder on the Linux server to access with a Windows computer, which will be good for backups. It can be treated like another hard drive and files can be transferred easily. It was a lot of work, one small mistake that I made in providing a name was the problem. Windows did not like the use of special characters, slashes like / or \ in the name of the folder! It kept telling me, I don’t have permission for the folder and that the path did not exist. I thought I was being smart naming the network folder the same as it appears on the server computer, /files/erick, that was a big mistake! I went crazy checking the firewall, checking the DNS names & addresses. Reading things online. Then I added a new folder with a simple name, just files, and it worked, so I changed all of the folder names to something simple and it worked fine! I will use the Samba shares mounted as drives, for backup of the Windows computers, in one location.

I did learn a useful command in the process of troubleshooting, running…

smbclient -l    //serveripaddress -u username

from the server CL lets you see all of the computers on the workgroup to make sure they show up and names are being resolved. If they look OK then you know you have that part working alright. As far as the firewall, it is off by default when Ubuntu Server installs. This can be confirmed by a dump of the iptables.

And of course, I installed the server with the SSH option turned on. So I can do all of this without having to be in front of the machine.

IP is set to static too. I learned that you can now set the DNS servers in the same config file as setting up static IP.