sshpass wait for keyboard input - sshpass

When using sshpass how do I let it wait for keyboard input?
for an example
sshpass -p mypassword ssh username#hostname
That will make the connection to the host.
When I run it I wanted the connection wait after the password is appended to the host until I press "enter" on my keyboard.
Many Thanks

Its dual authentication. After my nomal pass i have a random key to add it on.
sshpass cannot do this kind of thing. You need something like expect, pexpect.

Related

Run command - terminal

IMPORTANT: that this is not just for this case, I want to create for example .bats to automate some things, then I would like to know how to make him wait for the command to return and interpret my next line as the answer.
How i can do .bat file answer one question comes of a command, for example:
I run it:
ssh -p port user#host
And then it require password, how in the next line i do it answer programatycally in same .bat?
I tryied:
ssh -p port user#host
PASSWORD
But dont works, he discart my PASSWORD and require it in the next line.
I don't believe there is a way to save your password. However, you may be able to set up key based authentication so that a password is not required.
> ssh-keygen
> ssh-copy-id -i ~/.ssh/mykey user#host
See https://www.ssh.com/ssh/copy-id for more info

How to non-interactively feed ssh with Time-based One-Time Password?

Some supercomputers require time-based one-time password (OTP) to login via ssh. I want to avoid typing the password every time and automate login/scp/rsync via bash script, in which I generate the one-time password and then pass the one-time password to ssh by using sshpass:
sshpass -p my_password_and_OTP ssh user#hostname
This sshpass works for usual ssh, but my testing indicates it does not work for ssh requiring one-time password. I am wondering whether there is a way to non-interactively feed ssh with Time-based One-Time Password.
Here is my solution using expect+oathtool:
#!/usr/bin/expect -f
set otp [exec oathtool --totp -b my_secrete_key]
set timeout -1
spawn scp a.f90 usrname#cori.nersc.gov:~/
expect "Password + OTP:"
send -- "my_passwd${otp}\r"
expect eof
I use oathtool to generate the one-time-password and store the result in a variable otp.

ssh in shell script, then execute commands after password

I'm trying to write a simple shell script to execute commands on my server box via ssh.
I'm not trying to pass a password within the shell script, I'm just wondering how I can get it to run commands on that box after the password is entered.
So far, when I execute my script, nothing happens after I enter the password. Or, it executes when I kill the ssh process.
I'm sure it's really easy, but I've been searching for hours and nothing has come up on the net, probably because nobody else needs to ask that.
Is there some way to do this natively within the shell? Thanks!
Look if you want to ssh without prompting password then you need a key authentication rather password authentication.
Else try;
sudo apt-get install sshpass
sshpass -p your_password ssh user#hostname
And to execute command at remote;
ssh user#host 'command'

SSH / rsync / scp with username and password (and host) as parameters

I'm figuring out how to best create a bash script that accepts username, password and host as input and can then use ssh/rsync/scp to connect. It seems that these programs only accept password that is given by the user via prompt.
Note: I am well familiar with SSH keys - my use case is a situation where one wants to programmatically place an SSH key to a server where a key does not exist.
My current solution is to use expect to answer the password prompt with the correct password (and provide all other information as parameters).
See https://gist.github.com/elnygren/965a6db4f3fd8e242e90
If you do not mind your password being visible to other users you could use sshpass as suggested in this answer:
sshpass -p<password> ssh <arguments>
The best solution for jobs like these (connecting anything over SSH, be it ssh itself, scp or rsync) is to use keys for authentification.
Then you can add your key to the auth manager (or just leave it without passphrase, but then be careful!) and use it to connect to the host.

Bash Script - SSH Connection

I am having difficulty passing a password through a bash script for an ssh connection. I have everything working, but it still prompts me for the password instead of pulling the stored password. Please take a look at the portion of the script below, and let me know if there is something obvious I'm doing wrong:
#! /bin/bash
echo "Please enter a username:"
read user
echo "please enter a password:"
read password
echo please enter an IP address:"
read ip
ssh "$user"#"$ip"
expect "password:"
send "<password>\r"
interact
I have tried different variations of the "send" line. For instance, I've tried "password\r" and password\r. I've also tried modifying the "expect" line to mirror the exact text returned by the attempted SSH connection.
Thanks for any help that can be provided.
SSH contains code to prevent password theft by redirecting standard I/O.
The correct solution is to generate a private/public key pair with ssh-keygen. Install the public key on the remote side. ssh-copy-id will help.
Then you can use the SSH agent to load the private key into memory and SSH won't ask for a password or key phrase.
Related:
https://askubuntu.com/questions/46930/how-can-i-set-up-password-less-ssh-login

Resources