From owner-freebsd-questions@FreeBSD.ORG Wed Oct 31 18:11:32 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7E82116A41B for ; Wed, 31 Oct 2007 18:11:32 +0000 (UTC) (envelope-from erik@cepheid.org) Received: from mail.cepheid.org (aleph.cepheid.org [72.232.60.94]) by mx1.freebsd.org (Postfix) with ESMTP id 55D9B13C4AC for ; Wed, 31 Oct 2007 18:11:32 +0000 (UTC) (envelope-from erik@cepheid.org) Received: by mail.cepheid.org (Postfix, from userid 1006) id 33BCF9B40A1; Wed, 31 Oct 2007 12:18:43 -0500 (CDT) Date: Wed, 31 Oct 2007 12:18:43 -0500 From: Erik Osterholm To: FreeBSD Questions Message-ID: <20071031171843.GA96908@aleph.cepheid.org> Mail-Followup-To: Erik Osterholm , FreeBSD Questions References: <62b856460710310231h3bc517cdl20300179ac6f1a39@mail.gmail.com> <62b856460710310620v588222edj620e8519643881a3@mail.gmail.com> <62b856460710310723j6d5e0928rf601195caf6a5deb@mail.gmail.com> <20071031150936.GA60294@brick.slightlystrange.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20071031150936.GA60294@brick.slightlystrange.org> User-Agent: Mutt/1.4.2.3i Subject: Re: ssh X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 Oct 2007 18:11:32 -0000 On Wed, Oct 31, 2007 at 03:09:36PM +0000, Daniel Bye wrote: > On Wed, Oct 31, 2007 at 03:23:57PM +0100, Michael Grant wrote: > > > Yeah, I misread your problem. Are you saying that you want to su to root, > > > but still have some variables set as they were on the account you sued from? > > > So you have a user named Michael, say, and you su to root, but when you ssh > > > you want Michael's .ssh to be the effective one? > > > > Well sort of. When I su, $HOME is set to my homedir and $USER set to > > mgrant. This is fine. However, ssh (when sued) doesn't read > > $HOME/.ssh, it reads /root/.ssh. And it's not defaulting to logging > > into the remote machine as $USER, it tries to log in as root. It does > > this because it's hardwired in the code more or less as follows (I've > > extracted the relevant code from ssh.c): > > > > original_real_uid = getuid(); > > pw = getpwuid(original_real_uid); > > sprintf(buf, "%s/%s", pw->pw_dir, "ssh-config"); > > read_config_file(buf); > > options.user = strdup(pw->pw_name); > > > > Like I said, it seems like a bug to me. Personally I would have done > > a getenv("HOME") and getenv("USER") myself instead of depending on the > > userid. Probably they had good reason for doing it the way they did > > it. > > Probably to do with the fact that both $HOME and $USER can be set by the > user to any arbitrary value: > > [daniel@torus:~] --->$ echo $USER $HOME > daniel /home/daniel > [daniel@torus:~] --->$ USER=root > [daniel@torus:~] --->$ HOME=/root > [daniel@torus:/home/daniel] --->$ echo $USER $HOME > root /root > [daniel@torus:/home/daniel] --->$ cd > [daniel@torus:~] --->$ pwd > /root > > Not so good for security! > > Dan But the same effect can be achieved by specifying the identity file: ssh -i /root/.ssh/id_dsa So this file still needs appropriate permissions to prevent misuse by other users. I'm pretty curious to know why the developers chose this path. If it's not actually a bug, but a security concern, then it would be a good learning experience for me! Erik