How to automatically add user account AND password with a Bash script?
You can run the passwd command and send it piped input. So, do something like:
echo thePassword | passwd theUsername --stdin
How to create a new username and password in Bash script?
Nevermind! I got it working!
This is my solution:
useradd $username -d /home/$username -m ;
echo $passwd | passwd $username --stdin;
echo "the account is setup"
How do I get my bash script to assign unique usernames automatically to new users?
Just put another loop around
i=$(($i+1))
USERNAM="user$i"
to skip over existing users:
while
i=$(($i+1))
USERNAM="user$i"
id $USERNAM
do :
done
bash shell automatically creating user - adduser
Always quote your variables unless you deliberately want to split the value into separate words.
sudo adduser --gecos "$fullname" --disabled-password --home "$home" "$username"
Also, you have to use double quotes around strings containing variables, not single quotes, if you want the variables to be expanded.
Difference between single and double quotes in Bash
So this line:
echo 'username:$password' | chpasswd
should be:
echo "username:$password" | chpasswd
Automatically insert username and password to run application in shell script
Got it to work by adding -u $UN -p $PWD
where $UN
and $PWD
are the username and password. I added the above text at the and of the line calling the app in the shell script.
How to input automatically when running a shell over SSH?
For general command-line automation, Expect is the classic tool. Or try pexpect if you're more comfortable with Python.
Here's a similar question that suggests using Expect: Use expect in bash script to provide password to SSH command
Related Topics
How to Search Contents of Multiple PDF Files
Difference Between Pid and Tid
Prevent Linux Thread from Being Interrupted by Scheduler
How to Convert Yyyymmddhhmmss to a Date Readable by 'Date'
Nuget on Linux: Error Getting Response Stream
Append Date to Filename in Linux
What Is the Purpose of the "-I" and "-T" Options for the "Docker Exec" Command
Sed with Literal String--Not Input File
Crontab Run Every 15 Minutes Except at 3Am
How Is the Linux Kernel Tested
How Pthread_Mutex_Lock Is Implemented
How to Set Rpath and Runpath with Gcc/Ld
Why Does Printf Overwrite the Ecx Register
Converting Serial Port Data to Tcp/Ip in a Linux Environment
Crt1.O: in Function '_Start': - Undefined Reference to 'Main' in Linux