How to add user for samba share through a shell script











up vote
1
down vote

favorite












Normally when i want to add a user for samba shared folder i use this command:



sudo smbpasswd -a <username>


and then this pops out



New SMB password:
Retype new SMB password:


and now I want to do this in a script but so that it doesn't stop there and ask me to insert password



this is my script:



##################################################################
#!/bin/bash

mkdir /var/www/html/test

tee -a /etc/samba/smb.conf << EOF
[test]

comment = Test folder
path = /var/www/html/test
browsable = yes
valid users = tester
read only = no
EOF

smbpasswd -a tester
password
password


...How can i hard code the password?










share|improve this question
























  • Use expect - admin-magazine.com/Articles/Automating-with-Expect-Scripts
    – Panther
    Apr 14 '17 at 20:50










  • that is 169 MB big package that i need to give me 2 lines of code....it's just too much....until someone gives a better solution i will type it in manually
    – lewis4u
    Apr 14 '17 at 20:53










  • Don't use sudo in your script, call the script with sudo sudo /path/to/script. , test if directory exists [ ! -d /var/www/html/test ] && mkdir -p /var/www/html/test , note the -p option. You can also test if /var/www/html/test already is within the conf file and if not add it (you should be able to figure it out).
    – Panther
    Apr 14 '17 at 20:56










  • Try google samba+scritp+to+add+user
    – Panther
    Apr 14 '17 at 21:01















up vote
1
down vote

favorite












Normally when i want to add a user for samba shared folder i use this command:



sudo smbpasswd -a <username>


and then this pops out



New SMB password:
Retype new SMB password:


and now I want to do this in a script but so that it doesn't stop there and ask me to insert password



this is my script:



##################################################################
#!/bin/bash

mkdir /var/www/html/test

tee -a /etc/samba/smb.conf << EOF
[test]

comment = Test folder
path = /var/www/html/test
browsable = yes
valid users = tester
read only = no
EOF

smbpasswd -a tester
password
password


...How can i hard code the password?










share|improve this question
























  • Use expect - admin-magazine.com/Articles/Automating-with-Expect-Scripts
    – Panther
    Apr 14 '17 at 20:50










  • that is 169 MB big package that i need to give me 2 lines of code....it's just too much....until someone gives a better solution i will type it in manually
    – lewis4u
    Apr 14 '17 at 20:53










  • Don't use sudo in your script, call the script with sudo sudo /path/to/script. , test if directory exists [ ! -d /var/www/html/test ] && mkdir -p /var/www/html/test , note the -p option. You can also test if /var/www/html/test already is within the conf file and if not add it (you should be able to figure it out).
    – Panther
    Apr 14 '17 at 20:56










  • Try google samba+scritp+to+add+user
    – Panther
    Apr 14 '17 at 21:01













up vote
1
down vote

favorite









up vote
1
down vote

favorite











Normally when i want to add a user for samba shared folder i use this command:



sudo smbpasswd -a <username>


and then this pops out



New SMB password:
Retype new SMB password:


and now I want to do this in a script but so that it doesn't stop there and ask me to insert password



this is my script:



##################################################################
#!/bin/bash

mkdir /var/www/html/test

tee -a /etc/samba/smb.conf << EOF
[test]

comment = Test folder
path = /var/www/html/test
browsable = yes
valid users = tester
read only = no
EOF

smbpasswd -a tester
password
password


...How can i hard code the password?










share|improve this question















Normally when i want to add a user for samba shared folder i use this command:



sudo smbpasswd -a <username>


and then this pops out



New SMB password:
Retype new SMB password:


and now I want to do this in a script but so that it doesn't stop there and ask me to insert password



this is my script:



##################################################################
#!/bin/bash

mkdir /var/www/html/test

tee -a /etc/samba/smb.conf << EOF
[test]

comment = Test folder
path = /var/www/html/test
browsable = yes
valid users = tester
read only = no
EOF

smbpasswd -a tester
password
password


...How can i hard code the password?







command-line samba user-management






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 6:34









muru

134k19282482




134k19282482










asked Apr 14 '17 at 20:43









lewis4u

2,21821427




2,21821427












  • Use expect - admin-magazine.com/Articles/Automating-with-Expect-Scripts
    – Panther
    Apr 14 '17 at 20:50










  • that is 169 MB big package that i need to give me 2 lines of code....it's just too much....until someone gives a better solution i will type it in manually
    – lewis4u
    Apr 14 '17 at 20:53










  • Don't use sudo in your script, call the script with sudo sudo /path/to/script. , test if directory exists [ ! -d /var/www/html/test ] && mkdir -p /var/www/html/test , note the -p option. You can also test if /var/www/html/test already is within the conf file and if not add it (you should be able to figure it out).
    – Panther
    Apr 14 '17 at 20:56










  • Try google samba+scritp+to+add+user
    – Panther
    Apr 14 '17 at 21:01


















  • Use expect - admin-magazine.com/Articles/Automating-with-Expect-Scripts
    – Panther
    Apr 14 '17 at 20:50










  • that is 169 MB big package that i need to give me 2 lines of code....it's just too much....until someone gives a better solution i will type it in manually
    – lewis4u
    Apr 14 '17 at 20:53










  • Don't use sudo in your script, call the script with sudo sudo /path/to/script. , test if directory exists [ ! -d /var/www/html/test ] && mkdir -p /var/www/html/test , note the -p option. You can also test if /var/www/html/test already is within the conf file and if not add it (you should be able to figure it out).
    – Panther
    Apr 14 '17 at 20:56










  • Try google samba+scritp+to+add+user
    – Panther
    Apr 14 '17 at 21:01
















Use expect - admin-magazine.com/Articles/Automating-with-Expect-Scripts
– Panther
Apr 14 '17 at 20:50




Use expect - admin-magazine.com/Articles/Automating-with-Expect-Scripts
– Panther
Apr 14 '17 at 20:50












that is 169 MB big package that i need to give me 2 lines of code....it's just too much....until someone gives a better solution i will type it in manually
– lewis4u
Apr 14 '17 at 20:53




that is 169 MB big package that i need to give me 2 lines of code....it's just too much....until someone gives a better solution i will type it in manually
– lewis4u
Apr 14 '17 at 20:53












Don't use sudo in your script, call the script with sudo sudo /path/to/script. , test if directory exists [ ! -d /var/www/html/test ] && mkdir -p /var/www/html/test , note the -p option. You can also test if /var/www/html/test already is within the conf file and if not add it (you should be able to figure it out).
– Panther
Apr 14 '17 at 20:56




Don't use sudo in your script, call the script with sudo sudo /path/to/script. , test if directory exists [ ! -d /var/www/html/test ] && mkdir -p /var/www/html/test , note the -p option. You can also test if /var/www/html/test already is within the conf file and if not add it (you should be able to figure it out).
– Panther
Apr 14 '17 at 20:56












Try google samba+scritp+to+add+user
– Panther
Apr 14 '17 at 21:01




Try google samba+scritp+to+add+user
– Panther
Apr 14 '17 at 21:01










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










I have found the solution on my own from this website



So the basic thing is that if you want to make a script for adding a specific user to the samba share goes like this:



This part of script is 'standard' and doesn't need to be changed except for the path of the folder you want to share:



##################################################################
#!/bin/bash

# make a folder if it doesn't exist
[ ! -d /var/www/html/test ] && mkdir -p /var/www/html/test

# append these lines at the end of the /etc/samba/smb.conf file
tee -a /etc/samba/smb.conf << EOF
[test]

comment = Test folder
path = /var/www/html/test
browsable = yes
valid users = tester
read only = no
EOF


and now if you want to:



add an existing user: append this to the 'standard script' above:



username='<existing_user_name>'
(echo "<password_for_user>"; sleep 1; echo "<password_for_user>" ) | sudo smbpasswd -s -a $username


add a new user that doesn't exist in OS: append this to 'standard script' above:



username='<new_user_name>'
useradd -m $username
(echo "<password_for_user>"; sleep 1; echo "<password_for_user>";) | passwd $username
(echo "<password_for_user>"; sleep 1; echo "<password_for_user>" ) | sudo smbpasswd -s -a $username





share|improve this answer























  • Ok i will do it today. I just woke up
    – lewis4u
    Apr 15 '17 at 7:52










  • I hope this is explained better and that the user who down voted me will give a feedback if it's still not good?
    – lewis4u
    Apr 15 '17 at 10:30











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f904870%2fhow-to-add-user-for-samba-share-through-a-shell-script%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










I have found the solution on my own from this website



So the basic thing is that if you want to make a script for adding a specific user to the samba share goes like this:



This part of script is 'standard' and doesn't need to be changed except for the path of the folder you want to share:



##################################################################
#!/bin/bash

# make a folder if it doesn't exist
[ ! -d /var/www/html/test ] && mkdir -p /var/www/html/test

# append these lines at the end of the /etc/samba/smb.conf file
tee -a /etc/samba/smb.conf << EOF
[test]

comment = Test folder
path = /var/www/html/test
browsable = yes
valid users = tester
read only = no
EOF


and now if you want to:



add an existing user: append this to the 'standard script' above:



username='<existing_user_name>'
(echo "<password_for_user>"; sleep 1; echo "<password_for_user>" ) | sudo smbpasswd -s -a $username


add a new user that doesn't exist in OS: append this to 'standard script' above:



username='<new_user_name>'
useradd -m $username
(echo "<password_for_user>"; sleep 1; echo "<password_for_user>";) | passwd $username
(echo "<password_for_user>"; sleep 1; echo "<password_for_user>" ) | sudo smbpasswd -s -a $username





share|improve this answer























  • Ok i will do it today. I just woke up
    – lewis4u
    Apr 15 '17 at 7:52










  • I hope this is explained better and that the user who down voted me will give a feedback if it's still not good?
    – lewis4u
    Apr 15 '17 at 10:30















up vote
2
down vote



accepted










I have found the solution on my own from this website



So the basic thing is that if you want to make a script for adding a specific user to the samba share goes like this:



This part of script is 'standard' and doesn't need to be changed except for the path of the folder you want to share:



##################################################################
#!/bin/bash

# make a folder if it doesn't exist
[ ! -d /var/www/html/test ] && mkdir -p /var/www/html/test

# append these lines at the end of the /etc/samba/smb.conf file
tee -a /etc/samba/smb.conf << EOF
[test]

comment = Test folder
path = /var/www/html/test
browsable = yes
valid users = tester
read only = no
EOF


and now if you want to:



add an existing user: append this to the 'standard script' above:



username='<existing_user_name>'
(echo "<password_for_user>"; sleep 1; echo "<password_for_user>" ) | sudo smbpasswd -s -a $username


add a new user that doesn't exist in OS: append this to 'standard script' above:



username='<new_user_name>'
useradd -m $username
(echo "<password_for_user>"; sleep 1; echo "<password_for_user>";) | passwd $username
(echo "<password_for_user>"; sleep 1; echo "<password_for_user>" ) | sudo smbpasswd -s -a $username





share|improve this answer























  • Ok i will do it today. I just woke up
    – lewis4u
    Apr 15 '17 at 7:52










  • I hope this is explained better and that the user who down voted me will give a feedback if it's still not good?
    – lewis4u
    Apr 15 '17 at 10:30













up vote
2
down vote



accepted







up vote
2
down vote



accepted






I have found the solution on my own from this website



So the basic thing is that if you want to make a script for adding a specific user to the samba share goes like this:



This part of script is 'standard' and doesn't need to be changed except for the path of the folder you want to share:



##################################################################
#!/bin/bash

# make a folder if it doesn't exist
[ ! -d /var/www/html/test ] && mkdir -p /var/www/html/test

# append these lines at the end of the /etc/samba/smb.conf file
tee -a /etc/samba/smb.conf << EOF
[test]

comment = Test folder
path = /var/www/html/test
browsable = yes
valid users = tester
read only = no
EOF


and now if you want to:



add an existing user: append this to the 'standard script' above:



username='<existing_user_name>'
(echo "<password_for_user>"; sleep 1; echo "<password_for_user>" ) | sudo smbpasswd -s -a $username


add a new user that doesn't exist in OS: append this to 'standard script' above:



username='<new_user_name>'
useradd -m $username
(echo "<password_for_user>"; sleep 1; echo "<password_for_user>";) | passwd $username
(echo "<password_for_user>"; sleep 1; echo "<password_for_user>" ) | sudo smbpasswd -s -a $username





share|improve this answer














I have found the solution on my own from this website



So the basic thing is that if you want to make a script for adding a specific user to the samba share goes like this:



This part of script is 'standard' and doesn't need to be changed except for the path of the folder you want to share:



##################################################################
#!/bin/bash

# make a folder if it doesn't exist
[ ! -d /var/www/html/test ] && mkdir -p /var/www/html/test

# append these lines at the end of the /etc/samba/smb.conf file
tee -a /etc/samba/smb.conf << EOF
[test]

comment = Test folder
path = /var/www/html/test
browsable = yes
valid users = tester
read only = no
EOF


and now if you want to:



add an existing user: append this to the 'standard script' above:



username='<existing_user_name>'
(echo "<password_for_user>"; sleep 1; echo "<password_for_user>" ) | sudo smbpasswd -s -a $username


add a new user that doesn't exist in OS: append this to 'standard script' above:



username='<new_user_name>'
useradd -m $username
(echo "<password_for_user>"; sleep 1; echo "<password_for_user>";) | passwd $username
(echo "<password_for_user>"; sleep 1; echo "<password_for_user>" ) | sudo smbpasswd -s -a $username






share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 23 '17 at 18:53

























answered Apr 14 '17 at 21:29









lewis4u

2,21821427




2,21821427












  • Ok i will do it today. I just woke up
    – lewis4u
    Apr 15 '17 at 7:52










  • I hope this is explained better and that the user who down voted me will give a feedback if it's still not good?
    – lewis4u
    Apr 15 '17 at 10:30


















  • Ok i will do it today. I just woke up
    – lewis4u
    Apr 15 '17 at 7:52










  • I hope this is explained better and that the user who down voted me will give a feedback if it's still not good?
    – lewis4u
    Apr 15 '17 at 10:30
















Ok i will do it today. I just woke up
– lewis4u
Apr 15 '17 at 7:52




Ok i will do it today. I just woke up
– lewis4u
Apr 15 '17 at 7:52












I hope this is explained better and that the user who down voted me will give a feedback if it's still not good?
– lewis4u
Apr 15 '17 at 10:30




I hope this is explained better and that the user who down voted me will give a feedback if it's still not good?
– lewis4u
Apr 15 '17 at 10:30


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f904870%2fhow-to-add-user-for-samba-share-through-a-shell-script%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Ellipse (mathématiques)

Quarter-circle Tiles

Mont Emei