You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jumpserver/genkey.sh

37 lines
785 B

#!/bin/bash
user=$1
password=$2
cwd (){
dir=$0
dirname $dir
}
dir=$(cwd)
. ${dir}/shell.conf
keyfile=${dir}/keys/${user}
rm -f ${keyfile}
gen_key() {
ssh-keygen -t rsa -f ${keyfile} -P $1
}
if [ -z $1 ] || [ -z $2 ];then
echo "Usage: ./script user password"
exit 3
fi
gen_key ${password}
mkdir -p /home/${user}/.ssh
#ssh -p ${host2_port} ${host2} "mkdir -p /home/$user/.ssh"
cat ${keyfile}.pub > /home/${user}/.ssh/authorized_keys
#ssh -p ${host2_port} ${host2} "cat > /home/$user/.ssh/authorized_keys" < ${keyfile}.pub
chmod 600 /home/${user}/.ssh/authorized_keys
#ssh -p ${host2_port} ${host2} "chmod 600 /home/$user/.ssh/authorized_keys"
chown -R ${user}:${user} /home/${user}/.ssh
#ssh -p ${host2_port} ${host2} "chown -R $user:$user /home/$user/.ssh"