forked from tylda-public/helpers
add ssh key and create nextcloud user
Co-authored-by: smoorg <smoorg@tylda.org>
This commit is contained in:
16
add_ssh_key.sh
Executable file
16
add_ssh_key.sh
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ -n "$1" ] && login=$1 || read -p "provide login: " login
|
||||
[ -n "$2" ] && ssh_key=$2 || read -p "provide ssh key: " ssh_key
|
||||
|
||||
ssh_dir=/home/$login/.ssh
|
||||
mkdir -p "$ssh_dir"
|
||||
[ ! -f "$ssh_dir/authorized_keys" ] && touch $ssh_dir/authorized_keys
|
||||
|
||||
# add it to authorized_keys but avoid adding it twice
|
||||
ak=$ssh_dir/authorized_keys
|
||||
[ ! grep "$ssh_key" $ak ] && echo "$ssh_key" >> $ak
|
||||
|
||||
# ssh wont work without it
|
||||
chmod -R 0700 /home/$login/.ssh
|
||||
chown -R $login:$login $ssh_dir
|
||||
Reference in New Issue
Block a user