LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 06-14-2016, 03:39 AM   #1
ilesterg
Member
 
Registered: Jul 2012
Location: München
Distribution: Debian, CentOS/RHEL
Posts: 587

Rep: Reputation: 72
SSH client not reading correct Host config


Hi,

My .ssh/config file looks like this:
Code:
Host *
  User user1
  IdentityFile /root/home/user1/id_rsa

Host host2
  Hostname host2.domain.com
  User user2
The problem is, when I do
Code:
ssh host2
it is asking for the passphrase for /root/home/user1/id_rsa. Why is that? I was expecting that the Host section to be read will be the 2nd one, in which case no private key is specified and thus should ask me for the user2 password.

Code:
-bash-3.2$ lsb_release -a
<cut>
Distributor ID: RedHatEnterpriseServer
Description:    Red Hat Enterprise Linux Server release 5.7 (Tikanga)
Release:        5.7
Codename:       Tikanga
-bash-3.2$ rpm -qa | grep ssh
openssh-4.3p2-72.el5_7.5
openssh-server-4.3p2-72.el5_7.5
openssh-clients-4.3p2-72.el5_7.5
sshpass-1.05-1.el5
-bash-3.2$ rpm -qi openssh-clients
Name        : openssh-clients              Relocations: (not relocatable)
Version     : 4.3p2                             Vendor: Red Hat, Inc.
Release     : 72.el5_7.5                    Build Date: Thu 18 Aug 2011 12:18:45 AM EDT
Install Date: Wed 26 Mar 2014 05:53:15 PM EDT      Build Host: x86-001.build.bos.redhat.com
Group       : Applications/Internet         Source RPM: openssh-4.3p2-72.el5_7.5.src.rpm
Size        : 862056                           License: BSD
Packager    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
URL         : http://www.openssh.com/portable.html
Summary     : The OpenSSH client applications
Description :
OpenSSH is a free version of SSH (Secure SHell), a program for logging
into and executing commands on a remote machine. This package includes
the clients necessary to make encrypted connections to SSH servers.
You'll also need to install the openssh package on OpenSSH clients.
Thanks!
 
Old 06-14-2016, 03:54 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by ilesterg View Post
I was expecting that the Host section to be read will be the 2nd one, in which case no private key is specified and thus should ask me for the user2 password.
Why would you expect that?

Host * is the first match, so that will be used.

Change the order of your entries so that Host * is the last case.

Last edited by TenTenths; 06-14-2016 at 03:55 AM.
 
Old 06-14-2016, 03:59 AM   #3
ilesterg
Member
 
Registered: Jul 2012
Location: München
Distribution: Debian, CentOS/RHEL
Posts: 587

Original Poster
Rep: Reputation: 72
I've seen a lot of examples online showing the * as the first entry. Tried putting the Host * at the bottom already, same output.
 
Old 06-14-2016, 04:03 AM   #4
ilesterg
Member
 
Registered: Jul 2012
Location: München
Distribution: Debian, CentOS/RHEL
Posts: 587

Original Poster
Rep: Reputation: 72
By the way, here's the output of ssh -vvv.
Code:
-bash-3.2$ ssh -vvv host2
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /root/home/thisuser/.ssh/config
debug1: Applying options for host2
debug1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to host2.domain.com [x.x.x.x] port 22.
debug1: Connection established.
 
Old 06-14-2016, 04:19 AM   #5
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
My bad, brain fade on my part.

So what you're telling ssh is that for host2 to use:
Code:
  Hostname host2.domain.com
  User user2
and inherit
Code:
  IdentityFile /root/home/user1/id_rsa
Did you try:
Code:
Host host2
  Hostname host2.domain.com
  User user2
  IdentityFile ''
 
Old 06-14-2016, 04:57 AM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by ilesterg View Post
Hi,

My .ssh/config file looks like this:
Code:
Host *
  User user1
  IdentityFile /root/home/user1/id_rsa
Is "My .ssh/config" the root user's .ssh/config?
 
Old 06-14-2016, 05:10 AM   #7
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,306
Blog Entries: 3

Rep: Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720
All the other host configuration will inherit the IdentityFile settings applied globally to Host *
And since IdentityFile can be used multiple times per host, adding another one won't overwrite or exclude the first. So with your current example configuration one way to do that is to do a negation.

Code:
Host * !host2
  User user1
  IdentityFile /root/home/user1/id_rsa

Host host2
  Hostname host2.domain.com
  User user2
Edit: but negation won't scale, for obvious reasons. It's better to make an inclusive pattern instead.

Last edited by Turbocapitalist; 06-14-2016 at 05:13 AM.
 
  


Reply

Tags
client, openssh, ssh



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
[SOLVED] ping reply unknown host but dig and host return correct IP kathy_lo Linux - Networking 6 11-18-2012 07:12 PM
please correct my samba config thetotzky04 Linux - Newbie 1 04-25-2009 09:17 AM
DISCUSSION: ssh w/ gtk programs (host-client display export) mrchaos LinuxAnswers Discussion 1 12-14-2005 01:50 PM
Is my Exim4 config file correct?... need help. ExCIA Debian 9 05-09-2005 02:58 PM
to 2.6.10 from 2.4.26 | ssh client | Host key verification failed kaN5300 Slackware 6 01-05-2005 10:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 10:08 PM.

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