blob: 4fe06d12b2ea3ad5a8370ed9abb50a532d9fe825 (
plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#!/bin/sh -e
# Copyright 2017 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if [ "$USER" != "root" ]; then
echo "adddropbox must be run as root"
exit 1;
fi
if [ ! -e ./adddropbox ]; then
echo "adddropbox must be run from framework directory"
exit 1;
fi
if [ "$2" = "" ]; then
echo "Syntax: adddropbox <userid> <SSH public key file>"
exit 1;
fi
USERID=$1
PUBKEY=$2
if [ ! -e ./request_pub.pem ]; then
echo "Generating request encryption key pair"
openssl genpkey -algorithm RSA -out request_priv.pem -pkeyopt rsa_keygen_bits:2048
chmod 600 request_priv.pem
openssl rsa -pubout -in request_priv.pem -out request_pub.pem
fi
REM=`echo $USERID | cut -c 9-`
if [ "$REM" != "" ]; then
echo "Userid character length limit is 8"
exit 1;
fi
if [ ! -e $PUBKEY ]; then
echo "Public key file doesn't exist : $PUBKEY"
exit 1;
fi
grep -q ssh-rsa $PUBKEY
if [ $? -ne 0 ]; then
echo "Public key doesn't appear to be in correct format"
exit 1;
fi
if [ -e /home/dropbox/$USERID ]; then
echo "Dropbox for $USERID already exists"
exit 1;
fi
# Ok, do this thing
echo "Creating new dropbox for $USERID"
useradd -s /bin/false -G signers -M $USERID
mkdir /home/$USERID
chown root:$USERID /home/$USERID
chmod 750 /home/$USERID
mkdir /home/dropbox/$USERID/
chown $USERID:signers /home/dropbox/$USERID
chmod 770 /home/dropbox/$USERID
cp ./request_pub.pem /home/dropbox/$USERID
mkdir /home/$USERID/dropbox
mount --bind /home/dropbox/$USERID/ /home/$USERID/dropbox
echo "/home/dropbox/$USERID/ /home/$USERID/dropbox none bind" >> /etc/fstab
echo "
Match User $USERID
ChrootDirectory /home/$USERID
ForceCommand internal-sftp
AllowTcpForwarding no
PermitTunnel no
X11Forwarding no
" >> /etc/ssh/sshd_config
cp $PUBKEY /etc/ssh/authorized_keys/$USERID
rm -f $PUBKEY
systemctl restart sshd
echo "Dropbox for $USERID setup"
echo "Next ensure a matching CCA profile exists and then run 'password_generate -profile $USERID -sender <signers email>'"
|