I have a list of around 100 servers that I need to add a user to. I have an ssh-rsa key I also need to add to the authorized keys file. I'm trying to accomplish this using a for loop but I'm not getting anywhere.
I use an alias to SSH to bastion (connect), and I can connect to the server but it halts at the prompt, then it won't continue on until I type exit at said prompt. Even then I think it's actually just executing the commands locally rather than remote.
I'm not able to use any third party tools so I have to use what's available in a default installation.
#!/bin/bash connect='ssh user@bastionserver -t --' adduser='adduser -disabled-password --gecos "a user account" -home /home/foobar foobar -q' mkdir='mkdir /home/foobar/.ssh' chmod='chmod -R 700 /home/foobar/.ssh/' chown='chown -R soc /home/foobar/' for server in $(cat server_list.txt) do $connect root@"$server" echo "$adduser" echo "$mkdir" echo "$chmod" echo "$chown" done
I can't figure this out! Any help appreciated.