I'm working a script that create user and add a key for that user so he can use that key with his username to SSH into my VM
Ex. user = john
useradd -m john &&
cd ~/.ssh/ &&
rm -rf tmp_rsa* &&
ssh-keygen -t rsa -b 4096 -C "john@email.com" -N '' -f john_rsa &&
echo "#tmp_rsa" >> authorized_keys &&
cat john_rsa.pub >> authorized_keys &&
cat authorized_keys &&
service ssh restart &&
echo ">>> Done"
Is the above script is correct to acheive what I want ?
I tried connect with UN : john, and the key generated john_rsa.
I got
Thanks to @marosg and @Takkat
Here is my updated script
adduser -m john &&
cd ~/.ssh/ &&
rm -rf tmp_rsa* &&
ssh-keygen -t rsa -b 4096 -C "john@email.com" -N '' -f john_rsa &&
echo "#tmp_rsa" >> ~john/.ssh/authorized_keys &&
cat john_rsa.pub >> ~john/.ssh/authorized_keys &&
cat authorized_keys &&
echo ">>> Done"
