'How to add Multiple user acccount with check and SSH key using Bash script
Based on my requirement in my dev server, I have Created a Linux function that will create a dev user,(Take the user's first name and create a Linux user )
we have a devs group in our developer server, and now want to create a Linux function for 10 plus developers (user)
as a requirement If any of the '$1' directories exist, it would throw a notice to the executor. our developer will have their own key my plan was not to copy the key. we could pass the key in when this is executed, or have this generate the key and output it on completion.
I have tried this code:
#!/bin/bash
CREATE_USER_NAME="pi"
# Create account
echo "============= now create an account ============="
sudo useradd -s /usr/bin/fish -m $CREATE_USER_NAME
sudo usermod -aG devs $CREATE_USER_NAME
sudo passwd $CREATE_USER_NAME
if getent passwd "$1" > /dev/null 2>&1; then
echo "yes the user exists"
else
echo "No, the user does not exist"
fi
mkdir -p /home/santosh/.ssh
chmod 0700 /home/santosh/.ssh
touch /home/santosh/.ssh/authorized_keys
chmod 600 /home/santosh/.ssh/authorized_keys
sudo mkdir -p /var/www/html/santosh-dev.jove.com/
sudo chown -R santosh /var/www/html/santosh-dev.jove.com/
sudo mkdir -p /var/log/httpd/santosh-dev.jove.com/
sudo chown -R santosh /var/log/httpd/santosh-dev.jove.com/
#
Output I Received:
[santosh@skb Desktop]$ ./user1.sh
============= now create an account =============
[sudo] password for santosh:
useradd: user 'pi' already exists
Changing password for user pi.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
No, the user does not exist
what is the best advice here! I'm unable to figure it what is wrong here? can anyone guide me on it!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|