linux - Can't add key to remote machine for user -
i writing script add user aws ec2 instance. below shell script.
file=$2 user=$1 user1="ec2-user" basekey="/home/user-home/some-folder/test.pem" keyfile=$3 file1=`cat /home/user-home/.ssh/id_rsa.pub` line in `cat $file` ssh -i $basekey -o stricthostkeychecking=no $user1@$line sudo useradd -m -d /home/$user $user ssh -i $basekey -o stricthostkeychecking=no $user1@$line sudo mkdir /home/$user/.ssh ssh -i $basekey -o stricthostkeychecking=no $user1@$line sudo touch /home/$user/.ssh/authorized_keys ssh -i $basekey -o stricthostkeychecking=no $user1@$line sudo chmod 777 /home/$user/.ssh ssh -i $basekey -o stricthostkeychecking=no $user1@$line sudo chmod 777 /home/$user/.ssh/authorized_keys scp -i $basekey -o stricthostkeychecking=no $keyfile $user1@$line:/home/$user1/ sleep 10 ssh -i $basekey -o stricthostkeychecking=no $user1@$line sudo cat /home/$user1/id_rsa.pub > /home/$user/.ssh/authorized_keys ssh -i $basekey -o stricthostkeychecking=no $user1@$line sudo cat /home/$user/.ssh/authorized_keys echo ssh -i $basekey -o stricthostkeychecking=no $user1@$line sudo chmod 600 /home/$user/.ssh/authorized_keys echo ssh -i $basekey -o stricthostkeychecking=no $user1@$line sudo chown $user.$user /home/$user/.ssh/authorized_keys echo ssh -i $basekey -o stricthostkeychecking=no $user1@$line sudo chmod 700 /home/$user/.ssh echo ssh -i $basekey -o stricthostkeychecking=no $user1@$line sudo chown $user.$user /home/$user/.ssh done
i getting below error though file present there.
./dev-enable.sh: line 24: /home/devuser/.ssh/authorized_keys: no such file or directory
i can't find way interpolate particular line. appreciate on this.
i able resolve issue no such file or directory. looking @ wrong part of command. able resolve using interpolation , correct syntax of shell command. below correct command handle such situation.
ssh -i $basekey -o stricthostkeychecking=no $user1@$line sudo bash -c "'cat > /home/$user/.ssh/authorized_keys'" < $file1
and file1 defined below
file1=/home/user-home/.ssh/id_rsa.pub
Comments
Post a Comment