What i'm trying to do is the following.
SSH to remote host.
Append the public_keys in the logged in users authorized_keys file to all the users .ssh/authorized_keys file.
I've run into problem when trying to perform sudo & cat with password in one line. Anyone have an idea how to solve this?
One of the ways i've tried achieving this.
ssh -t $userHost -p $remotePort \
"for localUser in $(ls /home | grep -v $USER); \
do sudo mkdir -p /home/$localUser/.ssh && \
cat /home/$USER/.ssh/authorized_keys | sudo tee --append \
/home/$localUser/.ssh/authorized_keys > /dev/null; done"
But the sudo command doesnt seem work as an ssh command. NOPASSWD in the sudoers file is not an option.