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 http://programminglinuxblog.blogspot.com/2008/02/automatic-ssh-login-script-all.html
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.
#!/bin/bash
if [ ! $1 ]; then
echo "usage: pushssh.sh user@remoteserver "
exit
fi
PORT=22
if [ $2 ]; then
PORT=$2
fi
# Uploads your id_rsa.pub to the specified host, wrapped for readability
if [ ! -r ${HOME}/.ssh/id_rsa.pub ]; then
ssh-keygen -b 2048 -t rsa
fi
# 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/id_rsa.pub | ssh $1 -p $PORT "cat - >> .ssh/authorized_keys"
if [ $? -eq 0 ]; then
echo "Success"
fi
Once you are done, you just need to create another script say "execRemoteCmd" to execute the command you want as follows:
ssh root@164.99.184.111 $@
ssh root@164.99.184.111 $@
and use it as execRemoteCmd ls -ltr /chroot/lag/core.*
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment