Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.