mirror of
https://github.com/rancher/os.git
synced 2025-06-28 15:56:58 +00:00
21 lines
453 B
Bash
Executable File
21 lines
453 B
Bash
Executable File
#!/bin/bash
|
|
|
|
USERNAME=$1
|
|
HOME_DIR=$(grep ^$USERNAME /etc/passwd | cut -f6 -d:)
|
|
|
|
if [ ! -d $HOME_DIR/.ssh ]; then
|
|
mkdir -p $HOME_DIR/.ssh
|
|
chmod 0700 $HOME_DIR/.ssh
|
|
fi
|
|
|
|
if [ ! -e $HOME_DIR/.ssh/authorized_keys ]; then
|
|
touch $HOME_DIR/.ssh/authorized_keys
|
|
chmod 0600 $HOME_DIR/.ssh/authorized_keys
|
|
fi
|
|
|
|
if ! grep -q "$2" $HOME_DIR/.ssh/authorized_keys; then
|
|
echo "$2" >> $HOME_DIR/.ssh/authorized_keys
|
|
fi
|
|
|
|
chown -R $USERNAME $HOME_DIR/.ssh
|