ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I am working on a script that is used to add users in a LAN. I want to run this script on a workstation and add users on a central server by using the credentials which is supplied when the script prompts. I am using SSH with the public key copied onto the server so i can run commands in the server from the local machine. The username and password are stored in variables in the local machine and i am using the useradd command.
The problem is that we cant use the $password as plain text when using the -p option, but has to supply it as encrytpted. For this I am using the utility 'grub-md5-crypt'.
Now comes the real problem:
When I run the 'grub-md5-crypt', it promts us for the string two times. After that it presents us with the encrypted string. Now I want to get this encrypted string assigned to a variable and use it with the useradd command. Really I don't know how to implement this as I am a newbie to shell scripting. The most troubling thing is that I have finished my script and am waiting for this part. Please help...
marozsas has a good solution. If you don't want to install a new binary for this, however, you can probably use expect to perform the operation and capture output for you.
Here is a simple shell script which I placed in my /bin directory along with the expect script to add a user and encrypt their password for them. It depends upon 2 command line paramters 1=username 2=password
The bash script:
Code:
#!/bin/sh
# Add client to server
/usr/sbin/adduser -m $1
passwd.exp $1 $2
Now if the exp and sh scripts are in the same directory running the bash script with following username and password will work. I know it is very rough but it gets the job done for me.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.