Help in creating Sudo ssh script

Hi Experts,

I am new to Shell scripting. I want to login to a server using a script. The normal command I use is --> sudo ssh <Servername> . when i tried putting this into a txt format file and tried running, it throw an error "can't execute". I am an Admin and i have root access. Any help would be highly appreciated.

Hi, copy and paste your script into this forum.

Why are you using sudo to run the ssh command?

how are you running it? if ./script then you must give exe permissions using chmod to it before running.

Why run ssh as root? Why not just log in as root -- or better yet, don't. Does what you're doing really need root access?

I am trying to setup keys between 2 unix servers automatically. Thats what i am trying to do. Script should get source and destination server from me and shoudld login automatically.

---------- Post updated at 11:58 PM ---------- Previous update was at 11:51 PM ----------

I am using this command inside the script,just to verify if it works.

#! /bin/sh

--> ssh user@machine
asking password
--> sudo ssh user@machine
asking password.

I don't want to use -->sshpass -p<password> ssh user@machine because its secure and i dont want to save the password.

---------- Post updated 07-24-14 at 12:05 AM ---------- Previous update was 07-23-14 at 11:58 PM ----------

I am setting ssh keys between 2 *nix servers. Since I am an Security Administrator i need to set up lot of keys, so trying ti automate.

---------- Post updated at 01:47 AM ---------- Previous update was at 12:05 AM ----------

yes i did -->chmod +x myscript

You don't need root for this, though. You can just do ssh root@host without needing to run ssh as root.

But permitting root login for ssh is dicey. People will be trying to crack the password on that, best not to let them even try. What I generally do is:

ssh username@host sudo ...

where 'username' is set up to allow login with a key and sudo configured to allow that username.