shell script to create system account and add ssh

cat createuser.sh
#!/bin/bash
useradd username
cd /home/username
mkdir .ssh
chown username:username .ssh
chmod 700 .ssh
cd .ssh
echo "user-key-public key" >> authorized_keys
chown username:username authorized_keys
chmod 600 authorized_keys
echo "username ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers


##username is the username that needs to create an account
##user-key-public key is the user's own local public key The
script executes
bash createuser .sh

to see if the creation is successful
ls -la /home/username

     

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326162859&siteId=291194637
Recommended