1

I'm trying to build a raspberry pi cluster with 4 raspberry pis. I'm writing a script to add new users to the system such that the user can be added on all the 4 Pis without having to enter it multiple times. The command I'm using is adduser and I'm adding users on to all the 4 Pis using ssh. This is how that line in the script looks:

echo `ssh [email protected] "sudo adduser --shell /bin/bash user1"`

This is the line I'm using to add a new user. However, the command after this is where I need to change the password. If I use

sudo passwd user1

in the script, for each Pi, it prompts the user for a password 4 times. I don't want this to happen. Is there any way to get the user to enter the password once and store it in a variable and supply this to the passwd command?

2
  • Also, why echo with backticks instead of just the command? Commented May 20, 2014 at 19:03
  • I finally managed to solve it by using useradd instead of adduser and providing an option for the user to enter a password and encrypting it using the crypt() function in perl. These questions were helpful: stackoverflow.com/questions/1020534/… stackoverflow.com/questions/714915/… Commented May 22, 2014 at 18:42

2 Answers 2

0

Assuming there's still no "useradd" on Pi, I'd suggest you start looking into adduser's command line parameters?

adduser <username> -p <password> ...
Sign up to request clarification or add additional context in comments.

3 Comments

Actually, there is useradd command also. I just used adduser because I'm familiar with that command. There is --disable-password option in adduser but I think that only disables the password and allows you to log in via ssh or something. I don't really understand how it works. The useradd command has a --password option by which I can set a default password. I think I'll try that for now. Thanks!
@user3657965: I only know of --disabled-password which is useful if the Server's admin doesn't want to know a user's password. However, this still requires some action because the user should then set the password on the account using passwd. If you really want to automate the process of user creation I'd suggest useradd with the --passwd option. I do this quite often when preparing preconfigured Samba servers...
Thanks. I'm trying to do that now but I'm having a huge problem encrypting the password. Having never dealt with encryption before, I'm a little lost and the crypt() function apparently works for C? Any advice on how to go about this?
0

Here's a way to execute a number of commands through SSH with sudo on the remote side (in case logging in as root is not an option):

#!/bin/bash

ssh user@host 'sudo bash -es' <<EOF
command 1
command 2
EOF

-e to "fail on failure" (optional).

-s to read from STDIN.

(I gave it a quick try and it seems to work.)

Edit

I tried with -x (I like the feedback) but it made the output garbled, probably because STDIN and STDERR were "out of sync" (could be "solved" with 2>&1).

2 Comments

Thank you for your answer. I'm not sure this will help me though. Assuming command 1 is adduser and command 2 is passwd, the user will still get prompted for the new password every time these three lines execute (which in my case is 4 times).
@user3657965 Oh, I must've misunderstood then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.