-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathalidocklite_init.sh
More file actions
executable file
·66 lines (60 loc) · 1.97 KB
/
alidocklite_init.sh
File metadata and controls
executable file
·66 lines (60 loc) · 1.97 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
if [ -z "$USER_DIR" ]; then
if [ -e /etc/user_dir ]; then
export USER_DIR=`head -n 1 /etc/user_dir`
fi
fi
if [ -n "$USER_DIR" ]; then
if [ ! -d "$USER_DIR" ]; then
echo "Please mount $USER_DIR before running this script"
exit 1
fi
CURRENT_UID=`id -u`
DEST_UID=`stat -c "%u" /home/alidocklite`
useradd -d "/home/alidocklite" -s /bin/bash -M -N -u $DEST_UID $HOSTUSER
mkdir -p /home/alidocklite
chown $HOSTUSER /home/alidocklite
echo $HOSTUSER ALL=NOPASSWD:ALL >> /etc/sudoers
#. `dirname $BASH_SOURCE`/setuser.sh /home/alidocklite/ #$USER_DIR
# Create a SSH key for that user and authorize it
rm -rf "/home/alidocklite/.alidock-ssh"
mkdir -p "/home/alidocklite/.alidock-ssh"
pushd "/home/alidocklite/.alidock-ssh"
ssh-keygen -t rsa -f alidock.pem -N ''
mv alidock.pem.pub authorized_keys
popd
chmod -R u=rwX,g=rX,o=rX "/home/alidocklite/.alidock-ssh"
chmod -R 0600 "/home/alidocklite/.alidock-ssh/alidock.pem"
chown -R $HOSTUSER "/home/alidocklite/.alidock-ssh"
# Silence login messages ("Last login:...")
touch "/home/alidocklite/.hushlogin"
chown -R $HOSTUSER "/home/alidocklite/.hushlogin"
# Prepare sshd config
cat > /etc/ssh/sshd_config <<\EOF
# Automatically generated by alidock
HostKey /etc/ssh/ssh_host_rsa_key
SyslogFacility AUTHPRIV
AuthorizedKeysFile /home/alidocklite/.alidock-ssh/authorized_keys
PermitEmptyPasswords no
PasswordAuthentication no
ChallengeResponseAuthentication no
GSSAPIAuthentication no
GSSAPICleanupCredentials no
UsePAM yes
AllowAgentForwarding no
AllowTcpForwarding no
X11Forwarding yes
X11UseLocalhost no
Compression no
UseDNS no
PermitTunnel no
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
EOF
# Start the SSH server
#exec /usr/sbin/sshd -D
service ssh start
su - $HOSTUSER
fi