Browse Source

Specify an ssh public key when adding new user

Bob Mottram 9 years ago
parent
commit
1e87576868
3 changed files with 28 additions and 4 deletions
  1. 6
    0
      doc/EN/faq.org
  2. BIN
      man/freedombone-adduser.1.gz
  3. 22
    4
      src/freedombone-adduser

+ 6
- 0
doc/EN/faq.org View File

@@ -46,6 +46,12 @@ Yes. Freedombone can support a small number of users, for a "/friends and family
46 46
 freedombone-adduser [username]
47 47
 #+END_SRC
48 48
 
49
+Or optionally with an /ssh public key/, given either as a filename or directly pasted. Specifying an ssh key will allow the user to log in more securely if they need to (such as if they use the Mutt email client).
50
+
51
+#+BEGIN_SRC bash
52
+freedombone-adduser [username] [ssh public key]
53
+#+END_SRC
54
+
49 55
 Something to consider when having more than a single user on the system is the security situation. The original administrator user will have access to all of the data for other users (including their encryption keys), so if you do add extra users they need to have *complete trust* in the administrator.
50 56
 
51 57
 Another point is that Freedombone installations are not intended to support many users (maybe ten at most). Large numbers of users may make the system unstable, and the more users you have on one system the more it becomes a single point of failure and also perhaps a honeypot from the standpoint of adversaries. Think of what happened with Lavabit and the moral dilemma which an administrator can be faced with (comply with threats and betray the trust of your users or don't comply and suffer other consequences). Ideally, you never want to put yourself into a situation where you can be forced to betray others.

BIN
man/freedombone-adduser.1.gz View File


+ 22
- 4
src/freedombone-adduser View File

@@ -1,5 +1,6 @@
1 1
 #!/bin/bash
2 2
 MY_USERNAME=$1
3
+SSH_PUBLIC_KEY=$2
3 4
 GPG_KEYSERVER='hkp://keys.gnupg.net'
4 5
 SSH_PORT=2222
5 6
 COMPLETION_FILE=$HOME/freedombone-completed.txt
@@ -29,10 +30,27 @@ if [ ! -d /home/$MY_USERNAME ]; then
29 30
     exit 4
30 31
 fi
31 32
 
33
+if [ $2 ]; then
34
+    if [ -f $SSH_PUBLIC_KEY ]; then
35
+        mkdir /home/$MY_USERNAME/.ssh
36
+        cp $SSH_PUBLIC_KEY /home/$MY_USERNAME/.ssh/authorized_keys
37
+        echo 'ssh public key installed'
38
+    else
39
+        if [[ $SSH_PUBLIC_KEY == "ssh-"* ]]; then
40
+            mkdir /home/$MY_USERNAME/.ssh
41
+            echo $SSH_PUBLIC_KEY > /home/$MY_USERNAME/.ssh/authorized_keys
42
+            echo 'ssh public key installed'
43
+        else
44
+            echo 'The second parameter does not look like an ssh key'
45
+            exit 5
46
+        fi
47
+    fi
48
+fi
49
+
32 50
 if [ ! -d /home/$MY_USERNAME/Maildir ]; then
33 51
     echo 'Email directory was not created'
34 52
     userdel -r $MY_USERNAME
35
-    exit 5
53
+    exit 6
36 54
 fi
37 55
 
38 56
 if grep -q "set from=" /home/$MY_USERNAME/.muttrc; then
@@ -77,7 +95,7 @@ su -c "gpg --output $MY_GPG_PUBLIC_KEY --armor --export $MY_GPG_PUBLIC_KEY_ID" -
77 95
 if [ ! -f $MY_GPG_PUBLIC_KEY ]; then
78 96
     echo "GPG public key was not generated for $MY_USERNAME@$HOSTNAME $MY_GPG_PUBLIC_KEY_ID"
79 97
     userdel -r $MY_USERNAME
80
-    exit 6
98
+    exit 7
81 99
 fi
82 100
 
83 101
 # encrypt outgoing mail to the "sent" folder
@@ -131,7 +149,7 @@ freedombone-addxmpp -e "$MY_USERNAME@$HOSTNAME" -p "$NEW_USER_PASSWORD"
131 149
 if [ ! "$?" = "0" ]; then
132 150
     echo "XMPP account not created"
133 151
     userdel -r $MY_USERNAME
134
-    exit 7
152
+    exit 8
135 153
 fi
136 154
 
137 155
 if grep -q "Blog domain" $COMPLETION_FILE; then
@@ -139,7 +157,7 @@ if grep -q "Blog domain" $COMPLETION_FILE; then
139 157
     if [ ! -d /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users ]; then
140 158
         echo 'Blog users directory not found'
141 159
         userdel -r $MY_USERNAME
142
-        exit 8
160
+        exit 9
143 161
     fi
144 162
     echo ';Password' > /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
145 163
     echo "password = '$NEW_USER_PASSWORD'" >> /var/www/$FULLBLOG_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini