Script to connect with ssh to remote server with password

Vitalii Plagov

I'm connecting from one remote machine to many remote machines within one network. Username and password for all remote machines is the same. I want to write a script that will use my username and pass to login to machine. I can't install any tool on host machine (expect or sshpass). Copying public key to target remote machine doesn't make a sense since I rarely connect more than once to the same machine. Everyday - new machines.

Is it possible to set up ssh on host machine to be able to connect to remote machines without need to set something on target machines?

Local machine that I'm using to connect to the rest of the network - SUSE Linux Enterprise Server 11 SP3

icarus

Given the requirements I would install expect on my local machine and use it to add in effect a new command. Let us call the remote hosts one and many1, many2 and the local machine mybox. Something like this (untested)

#!/usr/bin/expect
# connect to "one"
spawn ssh username@one
# next lines shouldn't be needed, should have shared keys for "one"
expect "assword: "
# provide password for "one", ending with "\r"
send -- "the_password_for_username@one\r"
# mainloop
interact "~p" {
    send "ssh manyuser@[lindex $argv 0]\r"
    expect "yes/no)? " { send "yes\r" exp_continue } "assword: "
    send "the_password_for_many\r"
    }

Run this on mybox as ./script many1, it will connect you to one

Then when you want to connect to many1 just type ~p. It will run the ssh command, answer the "do you want to connect" question if asked, and provide the password.

Of course the standard comments about the insecurity of storing passwords in scripts apply. The other slight downside is that you need to dedicate a key sequence to this. Here I am using ~p but you could use a function key.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

ssh access to remote server without password - Windows

How to connect remote ssh server with socks proxy?

SSH2 in PHP to connect to remote server

public key or private key as a password of connect to remote database, ssh

Using bash script to connect to remote SQL Server

script ssh login to server and pass root password

Running local PowerShell script on remote SSH server

Perl script to check if possible to ssh to remote server

How to automatically enter username and password when prompted to connect to a remote server

How to escape @ in password when doing ssh to remote server?

ssh remote server on some port other than 22 without password

How can I ssh to a remote server with an automated password and no key?

Cannot Create mylsq user and password using ssh on remote server

Is your SSH password revealed when you attempt to connect to the wrong server?

Elasticsearch : connect to a remote server via. SSH (Node JS)

WinSCP to create an SSH tunnel to connect to a remote MySQL server

How can I connect to a remote X server _without_ ssh?

How to connect a local virtual machine to a remote server via SSH?

connect using SSH to a remote server from client running ubuntu 22.04

Can't connect to remote MySQL server on AWS, but ssh tunnel works

How to use SSH tunnel to connect to remote MySQL server?

How to connect to remote X-Server (logged in via ssh)

How to connect to Internet through a remote server via SSH connection

Unable to connect to remote server via SSH (requires public key)

Shell Script - how to scp into remote server and download files and protect password

Inputting a Password on a script for rsync to login to a remote server to complete rsync

How to run expect script from remote server via ssh?

ssh to remote server is timing out during the BASH script execution

How to run local shell script on remote server via SSH?