How can I create a user in linux using a bash script already knowing the username and password.
Lets say the username will be variable $username and password will be $password.
I also dont want it to print anything. I simply want to run a .sh file and have it create the user with a static variable I defined.
I am having issues trying to accomplish this. Also I assume I need to encrypt the text version of my password in sha-512
I tried this below no luck
sudo useradd -m -s /bin/bash -p $password $username
Thanks!
You haven't told us what exactly is going wrong but useradd requires a crypted (or otherwise possibly) password. It might be better to just let passwd do the work for you.
sudo useradd -m -s /bin/bash "$username"
echo "$password" | sudo passwd --stdin "$username"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With