Hi Guys,
As lately I’ve started my jorney to Linux world. I will share some nice script to add new users, which was shared to me by friend of mine.
To configure remote access, you need to change the configuration of ssh-server. In the file /etc/ssh/sshd_config, you must configure the following settings:
PermitRootLogin no
PermitEmptyPasswords no
PasswordAuthentication no
Before adding users to the server, you need to create a group:
You must also configure sudo: create a file /etc/sudoers.d/remote_ssh with the content:
In the directory /root create subdirectory “scripts” and create a file “newuser.sh” with the content below:
For Debian:
username=$1
comment=$2
if[ "$username"= ""]; then
error=1
fi
if[ "$comment"= ""]; then
error=1
fi
if[ $error ]; then
echo"usage: `basename $0` username ‘fullname’"
exit
fi
useradd-d /home/$username -c "$comment"-m "$username"
su-m "$username"-c "mkdir -m 0700 /home/$username/.ssh/"
su-m "$username"-c "touch /home/$username/.ssh/authorized_keys"
adduser $username admins
For CentOS
username=$1
comment=$2
if [ "$username" = "" ]; then
error=1
fi
if [ "$comment" = "" ]; then
error=1
fi
if [ $error ]; then
echo "usage: `basename $0` username ‘fullname’"
exit
fi
useradd -d /home/$username -c "$comment" "$username"
su -m "$username" -c "mkdir -m 0700 /home/$username/.ssh/"
su -m "$username" -c "touch /home/$username/.ssh/authorized_keys"
usermod -G admins $username
Permissions to this file must be changed to 700:
Regards,
Denis.
Leave a Reply