-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser-add
More file actions
26 lines (23 loc) · 715 Bytes
/
user-add
File metadata and controls
26 lines (23 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash
echo "enter username:"
read user
[ "${user}" == "" ] && echo "Error: empty username." && exit 1
/usr/sbin/useradd ${user}
password=`pwgen 10 1`
echo "${user}:${password}" | chpasswd
mkdir /home/${user}/.ssh -p
echo "enter ssh key:"
read sshkey
[ "${sshkey}" == "" ] && echo "No ssh key provided."
[ "${sshkey}" != "" ] && echo ${sshkey} >> /home/${user}/.ssh/authorized_keys
/usr/bin/chown -R ${user}:${user} /home/${user}
chmod 700 /home/${user}
chmod 700 /home/${user}/.ssh
chmod 400 /home/${user}/.ssh/authorized_keys
cat <<EOF
*******************************
user: ${user}
password: ${password}
ssh ${user}@$(hostname)
*******************************
EOF