ssh to another server with different username
expect, shell, ssh, unix
Solution
You want to use key-authentication http://ornellas.apanela.com/dokuwiki/pub:ssh_key_auth
- Generate your keys `ssh-keygen`
- Copy the keys to your new box `ssh-copy-id -i ~/.ssh/id_rsa.pub me@otherhost.com`
- ssh to other host without password `ssh me@otherhost.com`
Problem
I have to write a shell script which ssh to another server with other username without actually asking for a password from the user? Due to constraints I cannot use key based authentication. let, Source Server -- abc.efg.com Source UserName -- tom Source Password -- tom123 Destination Server -- xyz.efc.com Destination UserName -- bob destination Password -- bob123 I have to place the bash script in source server. Please let me know if something could be done using expect tool and/or sshpass. It is okay for me to hardcode the password for destination server in the bash script but I cannot bear an interactive session, simply when I run he script, I want to see the destination server logged in with another username. Thanks in Advance.