LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-05-2010, 03:46 AM   #1
G00fy
Member
 
Registered: Jul 2004
Location: Herent, Belgium, Europe, Earth
Distribution: Ubuntu 7.04
Posts: 102

Rep: Reputation: 15
SSH "say yes"


Hi,


How can I say "yes" to the ssh fingerprint authentication question automatically in my script?


Thanks
 
Old 04-05-2010, 03:57 AM   #2
bakdong
Member
 
Registered: Apr 2009
Posts: 214

Rep: Reputation: 44
Probably not a good idea to disable entirely (see Man in the middle attacks) but look at StrictHostKeyChecking in ssh.conf

ssh automatically maintains and checks a database containing identifica-
tion for all hosts it has ever been used with. Host keys are stored in
~/.ssh/known_hosts in the user's home directory. Additionally, the file
/etc/ssh/ssh_known_hosts is automatically checked for known hosts. Any
new hosts are automatically added to the user's file. If a host's iden-
tification ever changes, ssh warns about this and disables password
authentication to prevent server spoofing or man-in-the-middle attacks,
which could otherwise be used to circumvent the encryption. The
StrictHostKeyChecking option can be used to control logins to machines
whose host key is not known or has changed.
 
Old 04-05-2010, 04:09 AM   #3
G00fy
Member
 
Registered: Jul 2004
Location: Herent, Belgium, Europe, Earth
Distribution: Ubuntu 7.04
Posts: 102

Original Poster
Rep: Reputation: 15
Yes, I know. But I want to set up a basic environment within a shell script. In that I want to include the basic connection to a backup server (in order for the user not to have to say 'yes').
So I know the host key will be correct, but I just need to be able to say "yes" to it in an automatic way...

I also checked the sources of OpenSSH and it seems it is reading/writing from & to /dev/tty... Is there a possibility to say yes automatically?
 
Old 04-05-2010, 05:50 AM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by G00fy View Post
Yes, I know. But I want to set up a basic environment within a shell script. In that I want to include the basic connection to a backup server (in order for the user not to have to say 'yes').
So I know the host key will be correct, but I just need to be able to say "yes" to it in an automatic way...

I also checked the sources of OpenSSH and it seems it is reading/writing from & to /dev/tty... Is there a possibility to say yes automatically?
Start from

man yes

- maybe it'll work with 'ssh'.
 
Old 04-05-2010, 05:50 AM   #5
G00fy
Member
 
Registered: Jul 2004
Location: Herent, Belgium, Europe, Earth
Distribution: Ubuntu 7.04
Posts: 102

Original Poster
Rep: Reputation: 15
It doesn't
 
Old 04-05-2010, 05:51 AM   #6
G00fy
Member
 
Registered: Jul 2004
Location: Herent, Belgium, Europe, Earth
Distribution: Ubuntu 7.04
Posts: 102

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by bakdong View Post
Probably not a good idea to disable entirely (see Man in the middle attacks) but look at StrictHostKeyChecking in ssh.conf
You were partially (80%) right with this one:

ssh -o StrictHostKeyChecking=no root@other_ip

==> Auto-add to known_hosts file!
 
Old 04-05-2010, 05:54 AM   #7
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by G00fy View Post
It doesn't
Then 'expect': http://en.wikipedia.org/wiki/Expect .
 
Old 04-05-2010, 05:58 AM   #8
bakdong
Member
 
Registered: Apr 2009
Posts: 214

Rep: Reputation: 44
Thanks for the 80%! :-) Have you actually tried it using a batch file yet? I'm running batch file ssh connects on a machine that has StrictHostKeyChecking set to 'ask' in the ssh_config, and it doesn't stop for any input. I have an idea that there is a special case for batch files, but can't find any reference to this.

####### StrictHostKeyChecking
#
# If this flag is set to "yes", ssh will never automatically add
# host keys to the $HOME/.ssh/known_hosts and
# $HOME/.ssh/known_hosts2 files, and refuses to connect to hosts
# whose host key has changed. This provides maximum protection
# against trojan horse attacks. However, it can be somewhat annoy-
# ing if you don"t have good /etc/ssh_known_hosts and
# /etc/ssh_known_hosts2 files installed and frequently connect to
# new hosts. This option forces the user to manually add all new
# hosts. If this flag is set to "no", ssh will automatically add
# new host keys to the user known hosts files. If this flag is set
# to "ask", new host keys will be added to the user known host
# files only after the user has confirmed that is what they really
# want to do, and ssh will refuse to connect to hosts whose host
# key has changed. The host keys of known hosts will be verified
# automatically in all cases. The argument must be "yes", "no"
# or "ask". The default is "ask"
 
Old 04-05-2010, 06:00 AM   #9
bakdong
Member
 
Registered: Apr 2009
Posts: 214

Rep: Reputation: 44
Yes, you can also supply it on the command line using -o ....
 
Old 04-12-2010, 09:43 AM   #10
TimothyEBaldwin
Member
 
Registered: Mar 2009
Posts: 249

Rep: Reputation: 27
Why not supply the server public key along with the script. You can then specify it like:
Code:
ssh -o 'UserKnownHostsFile backup_server_key' backup_server
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SSH issue ""Server unexpectedly closed network connection" Errsta_Fonzarelli Linux - Software 12 05-24-2010 02:35 PM
Supplying "password" to "ssh" command paragkalra Linux - Networking 1 07-31-2008 05:19 AM
Why does "crond" sleep and "ssh" hung up? Chowroc Linux - Networking 0 01-12-2006 12:24 AM
"socks5" -> "http" proxy protocol, or ssh tunnel to sock5 ? I'm beyond http p vmicho Linux - Networking 2 12-16-2003 05:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration