sh SHELL:使用密钥创建用户(不稳定)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh SHELL:使用密钥创建用户(不稳定)相关的知识,希望对你有一定的参考价值。

#!/bin/bash
# Stop on any errors
set -e

NEWUSER=$1
USERPUBKEY=$2

if [ -z "$NEWUSER" ]; then
        echo "Username required"
        exit 1;
fi

if [ -z "$USERPUBKEY" ]; then
        echo "Public key required - Enclose argument in quotes!"
        exit 1;
fi

#1.) Create a new user.
useradd -d /home/$NEWUSER -s /bin/bash -m $NEWUSER

#2.) Create a local public/private key pair as the user.
su - -c "ssh-keygen -q -t rsa -f ~/.ssh/id_rsa -N ''" $NEWUSER

#3.) Create an authorized_keys file with their external public key,
su - -c "echo $USERPUBKEY > .ssh/authorized_keys" $NEWUSER

#4.) Adjust the authorized_keys permissions
su - -c "chmod 600 .ssh/authorized_keys" $NEWUSER

#5.) More steps?

以上是关于sh SHELL:使用密钥创建用户(不稳定)的主要内容,如果未能解决你的问题,请参考以下文章