Wednesday 21 April, 2010

ssh auto login script

Finding the script for ssh auto login is not at all difficult. Thinking that, I hadn't stored the link that I found as useful. Later when I tried to get that link, it took me some 10 mins to get the same link, and so, thought of blogging it.
Copied the below script from

Below script takes care of copying your certificate content into the remote box, which is not the case with other scripts found at different locations. Also, you can learn shell script with this script.


if [ ! $1 ]; then
echo "usage: user@remoteserver "


if [ $2 ]; then

# Uploads your to the specified host, wrapped for readability

if [ ! -r ${HOME}/.ssh/ ]; then
ssh-keygen -b 2048 -t rsa

# Make sure auth file exists and chmod to 600

ssh $1 -p $PORT 0> echo "mkdir ~/.ssh; touch ~/.ssh/authorized_keys;
chmod u+rw .ssh/authorized_keys"

# Append to the copy on the remote server

cat ~/.ssh/ | ssh $1 -p $PORT "cat - >> .ssh/authorized_keys"

if [ $? -eq 0 ]; then
echo "Success"

Once you are done, you just need to create another script say "execRemoteCmd" to execute the command you want as follows:
ssh root@ $@
ssh root@ $@
and use it as execRemoteCmd ls -ltr /chroot/lag/core.*

No comments: