How to do remote ssh non-interactively

Jill448 picture Jill448 · Jun 13, 2013 · Viewed 17.8k times · Source

I am trying to connect to a remote host from my local host through the below command.But there was a setting in the remote host that soon after we login it will prompt to enter a badge ID,password and reason for logging in, because it was coded like that in profile file on remote-host How can I overcome those steps and login directly non-interactively, without disturbing the code in profile.

jsmith@local-host$ ssh -t -t generic_userID@remote-host
Enter your badgeID, < exit > to abort:
Enter your password for <badgeID> :
Enter a one line justification for your interactive login to generic_userID

Answer

Arunas Bartisius picture Arunas Bartisius · Feb 4, 2018

Small amendment: to overcome remote server expect approach is required, but in case local script connects to bunch of remote servers, which configuration may be broken, just use SSH options:

ssh -f -q -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null USER@TARGETSYSTEM

This will omit ask for password in case there is no ssh_key setup, exit silently and continue with script/other hosts.

Puts ssh to background with -f, which is required when calling ssh command from sh (batch) file to remove local console redirect to remote input (implies -n).