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?
command-line samba user-management
add a comment |
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?
command-line samba user-management
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 sudosudo /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
add a comment |
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?
command-line samba user-management
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
command-line samba user-management
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 sudosudo /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
add a comment |
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 sudosudo /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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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