From owner-freebsd-questions@FreeBSD.ORG Wed Oct 31 14:51:00 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 2DD1216A417 for ; Wed, 31 Oct 2007 14:51:00 +0000 (UTC) (envelope-from michael.grant@gmail.com) Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.176]) by mx1.freebsd.org (Postfix) with ESMTP id D3BC113C481 for ; Wed, 31 Oct 2007 14:50:59 +0000 (UTC) (envelope-from michael.grant@gmail.com) Received: by py-out-1112.google.com with SMTP id u77so338874pyb for ; Wed, 31 Oct 2007 07:50:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=559E7lp6DV2tz9Gow/ONMv8UA/XTaa+Ai/aJ/E2hrIY=; b=uHSJH39wRkQUV6bibMrUkBl2Rq8ocFb8/HbkFMrU7ij/W0Zb3JAO105f+MN5iSyKoUGpFkFD50vWpKpzxOZ5R85XfCoWzEGupjeygI0Nb5PHBpp3UADUcaO5trpsa1UtgZOg2thOGXYrnzofPscJtRnb/xBWGM81vez2idQgYZM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=HljIiKlanvQpsk1PaUGAwgiuv0/WKmMu0ffzXmIKgg8uODuFAcXDVGdF0uXkSSeH2DicRxVkJsrYj+fOV/8fqmxe36iXcQo0vqhoyLh0VpCo/+1+X3Z5R4BR6iVcBUNoktvrWJUO2WcIGjt5EuXo3LLoYHePLTB5Viab5D1CLsI= Received: by 10.65.44.5 with SMTP id w5mr1291906qbj.1193840637968; Wed, 31 Oct 2007 07:23:57 -0700 (PDT) Received: by 10.64.251.5 with HTTP; Wed, 31 Oct 2007 07:23:57 -0700 (PDT) Message-ID: <62b856460710310723j6d5e0928rf601195caf6a5deb@mail.gmail.com> Date: Wed, 31 Oct 2007 15:23:57 +0100 From: "Michael Grant" Sender: michael.grant@gmail.com To: James In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <62b856460710310231h3bc517cdl20300179ac6f1a39@mail.gmail.com> <62b856460710310620v588222edj620e8519643881a3@mail.gmail.com> X-Google-Sender-Auth: 77cf9d254ee63b6e Cc: FreeBSD Questions 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 14:51:00 -0000 On 10/31/07, James wrote: > > > On 10/31/07, Michael Grant wrote: > > On 10/31/07, James wrote: > > > > > > > > > > > > On 10/31/07, Michael Grant wrote: > > > > > > > > If I'm sued as root and I ssh somewhere, ssh/scp reads it's files from > > > > /root/.ssh/. The docs say it reads from ~/.ssh which is what I want, > > > > but it's not doing that. When sued, the shell is properly expanding ~ > > > > to my home dir. > > > > > > > > Anyone know of a way around this behavior? > > > > > > > > Michael Grant > > > > > > > > > su - root > > > > Nope. One other suggestion was 'su -l root'. This does not change > > the situation either. > > > > I went into the source for ssh and it does a getuid() and then gets > > the homedir of that uid. So no amount of fooling with su is gonig to > > fix this. I guess it's like this for security reasons, it sure seems > > like a bug to me. I'd have used the HOME enviroment variable. > > > > So far, the best fix I've found is to create some aliases in bash as > follows: > > > > alias scp="scp -o User=username -i ~/.ssh/id_rsa" > > alias ssh="ssh -l username -i ~/.ssh/id_rsa" > > alias rsync="rsync -op -e 'ssh -l username -i /home/username/.ssh/id_rsa'" > > > > > > 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. So I think the problem is unsolvable using options to su. Only solution I found so far was the aliases above. Michael Grant