Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a bash script, I want to know know how to pipe in answers like for example:

ssh -l username -i /home/ubuntu/.ssh/id < yes

The ssh connection would ask if I would like to continue the connection and I want to pipe in the answer yes automatically and enter me in, but my script "< yes" doesn't seem to work. Does anyone know how to properly type and pipe the response "yes" in bash under Ubuntu?

share|improve this question

You usually are only asked if you want to connect when ssh is performing host key checking. Instead of trying to disable by using expect or a pipe, perhaps you could just disable it in your ssh configuration.

Add StrictHostKeyChecking no to your ~/.ssh/config, and ssh will no longer ask you if you want to connect, it will just connect.

share|improve this answer
+1 for solving the actual problem. – grawity Nov 1 '09 at 11:55

Use ssh -o "StrictHostKeyChecking no" -l username -i /home/ubuntu/.ssh/id to avoid the question altogether.

share|improve this answer

First of all, you should have tried this, instead of < yes:

$ echo "yes" | ssh -l username -i /home/ubuntu/.ssh/id

Secondly, not even this will work because ssh doesn't read the answer from stdin, it reads it directly from the terminal, so you'll need something like Expect:

$ expect -c 'spawn dislocate ssh -l username -i /home/ciupicri/.ssh/id_rsa test3
expect {
	"(yes/no)? " {
		send "yes\n"
		expect {
			"Warn" exit
$ dislocate

dislocate is a command that comes with Expect (at least on Fedora). Answer with y when asked connect? [y].

You could also try using pexpect, a pure Python Expect-like module. Check out its and examples.

share|improve this answer
do you mind giving me an example? – UbuntuUser Nov 1 '09 at 3:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.