Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am writing a script to copy the linux user passwords to samba on ubuntu server 10.04. I am using samba 3 with tdbsam backend.

1) How do I (if possible) copy accounts (user/password) from linux to samba using a shell script?

2) How do I find out in my script if a certain user is in the samba user db and has a password and is activated? I need this as my script is run more often and on subsequent runs I would need to find out if the user is already present. I would not copy or set password or activate if unneccesary.

This is the head of my config:

[global]
        workgroup = WORKGROUP
        server string = %h server
        security = SHARE
        obey pam restrictions = Yes
        pam password change = no
        passdb backend = tdbsam
        unix password sync = no
        syslog = 0
        log file = /var/log/samba/log.%m
        max log size = 1000
        dns proxy = No
        panic action = /usr/share/samba/panic-action %d
        encrypt passwords = true
        invalid users = root   
        hosts allow = 192.168.0.1/24
share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

The samba password file and your system shadow files have different hashing schemes. I believe neither of them is reversible, so there's no way to convert between one and the other. The only way to synchronize the passwords is at the time they are changed by updating both files simultaneously from the user's input. That's the whole point of the unix password sync setting .

share|improve this answer
    
thank you. i have to give up on question 1 then. but would still be interesting to find out if a user is in the tdbsam and active or not by a script. –  user12096 Jan 27 '10 at 1:32
add comment

I decided to switch back to smbpasswd for now. And I decided not to sync passwords. I need a simple solutions that just works here now.

This is the head of the config now:

[global]
         workgroup = WORKGROUP
         security = SHARE
         passdb backend = smbpasswd:/etc/samba/smbpasswd   
         unix password sync = no
         syslog = 0
         log file = /var/log/samba/log.%m
         max log size = 1000

And this is the script I will be running on initial install and from time to time:

USER=samwin                           
cat /etc/samba/smbpasswd | grep -e "^$USER:" 
if [ $? -ne 0 ]; then       
  echo "Adding Samba user USER:"  
  smbpasswd -a $USER 
else               
  echo "Samba user $USER already present." 
fi

I am still curious for the answer of my question above for future installs and I will accept the answer that fits best.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.