Automatic set no password SSH login
Hello all,
Ive been bouncing ideas lately on how to make a script that automatizes the process of copyind id_rsa.pub into the authorized_keys file, and this are the needs the script will do...
1. Generates SSH key automatically
This one is easy,
ssh-keygen -b 2048 -t rsa -f $(HOME)/.ssh/id_rsa -N ""
2. Makes sure authorized_keys file exists in remote server if it does not it creates it and chmods it to 600, I use expect here...
spawn ssh root@serveraddress 0> echo "mkdir ~/.ssh; touch ~/.ssh/authorized_keys; chmod u+rw .ssh/authorized_keys"
expect "*?assword:*"
send -- "rootpass\r"
Until here I got it working problem comes here, shell prompts error that says it cannot run spawn again and im not quite sure im doing it right!
3. Copy the contents of id_rsa.pub to authorized_key file in the remote server.
I tried the following command,
cat ~/.ssh/id_rsa.pub | ssh root@serveraddress "tee -a .ssh/authorized_keys"
but it does not work, permission denied, but im supossedly login in as root.
4. When all has worked and its all done I will do a restoration of a ntfs image with ntfsclone and modify the current grub so that the partition is recognized and booted into the editing of the grub menu.lst I figure it would be something like
echo "(whatever here)" | tee -a /boot/grub/menu.lst
and the ntfs thing like this:
ssh host ’cat backup.img.gz’ | gunzip -c |ntfsclone --restore-image --overwrite /dev/hda1
Now, this is to be done in one script, and what I have done is run the command separately to see how they work, but once I start to join them in order to get only one script to do this I get confused...
Im starting to learn bash scripting and expect scripting, and I really will use lots of your help with this script...
Thank you
|