RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 746961 - ssh-keygen cannot create key outside of ~/.ssh directory
Summary: ssh-keygen cannot create key outside of ~/.ssh directory
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: selinux-policy
Version: 6.2
Hardware: All
OS: Linux
unspecified
low
Target Milestone: rc
: ---
Assignee: Miroslav Grepl
QA Contact: Milos Malik
URL:
Whiteboard:
: 751828 (view as bug list)
Depends On: 746290
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-10-18 12:23 UTC by Matěj Cepl
Modified: 2012-06-20 12:27 UTC (History)
10 users (show)

Fixed In Version:
Doc Type: Enhancement
Doc Text:
Clone Of: 746290
Environment:
Last Closed: 2012-06-20 12:27:57 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2012:0780 0 normal SHIPPED_LIVE selinux-policy bug fix and enhancement update 2012-06-19 20:34:59 UTC

Description Matěj Cepl 2011-10-18 12:23:47 UTC
I have originally observed this issue on RHEL 6.2.

+++ This bug was initially created as a clone of Bug #746290 +++

So, following the orders of the Fedora project people I have decided to recreate my ssh keys. And this is what happens:

mitmanek:~ $ cd
mitmanek:~ $ ssh-keygen -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/matej/.ssh/id_rsa): id_fedora_rsa
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
open id_fedora_rsa failed: Permission denied.
Saving the key failed: id_fedora_rsa.
mitmanek:~ $ restorecon -v -R .ssh
mitmanek:~ $

Of course, it was my fault, that I forgot that keys have to be generated in ~/.ssh and not anywhere else because of SELinux, but it would be helpful if when getting a relative path (like in this case) ssh-keygen defaulted to ~/.ssh rather than to the current working directory.

Thank you

--- Additional comment from dwalsh on 2011-10-14 14:16:13 EDT ---

We could fix the SELinux but this could be a problem from a security point of view, since the ~/.ssh directory tends to be a protected directory.  I think if the user specifies a file without a path it should default to ~/.ssh

--- Additional comment from tmraz on 2011-10-17 03:42:55 EDT ---

I think SELinux should allow ssh-keygen writing anywhere. Basically ssh-keygen is a simple admin/user called local tool, not connecting anywhere, and it should be unconfined.

As for it defaulting to .ssh directory - this should be changed upstream first.

--- Additional comment from mgrepl on 2011-10-17 04:13:03 EDT ---

We might want to think about removing a transition to ssh-keygen at all since we have file name transition now so .ssh dir will create with the correct label.

Matej,

chcon -t bin_t `which ssh-keygen`

should work.

--- Additional comment from tmraz on 2011-10-17 04:20:16 EDT ---

Yes, Miroslav, I agree.

--- Additional comment from dwalsh on 2011-10-17 12:31:03 EDT ---

Yes in Rawhide we want to remove transition from user roles.

--- Additional comment from dwalsh on 2011-10-17 12:38:03 EDT ---

Removed transition in selinux-policy-3.10.0-41.fc16

Comment 2 Daniel Walsh 2011-10-18 12:39:05 UTC
Well since we do not have the file name transitions in RHEL6 we do not want to remove the transition from user roles to ssh-keygen.

Comment 3 RHEL Program Management 2011-10-25 05:49:34 UTC
Since RHEL 6.2 External Beta has begun, and this bug remains
unresolved, it has been rejected as it is not proposed as
exception or blocker.

Red Hat invites you to ask your support representative to
propose this request, if appropriate and relevant, in the
next release of Red Hat Enterprise Linux.

Comment 4 Miroslav Grepl 2011-11-07 18:04:24 UTC
*** Bug 751828 has been marked as a duplicate of this bug. ***

Comment 5 Petr Lautrbach 2011-12-08 15:46:13 UTC
ssh-keygen asks for file, not for name and also it offers filename with absolute path by default:
Enter file in which to save the key (/home/test/.ssh/id_rsa)

So I don't think that this behaviour should be changed.

But there is problem with SELinux policy which doesn't allow ssh-keygen to create key outside of ~/.ssh even for unconfined user.

type=AVC msg=audit(1323358944.706:324): avc:  denied  { write } for  pid=1578 comm="ssh-keygen" name="tmp" dev=vda3 ino=25 scontext=unconfined_u:unconfined_r:ssh_keygen_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=dir
type=AVC msg=audit(1323358944.706:324): avc:  denied  { add_name } for  pid=1578 comm="ssh-keygen" name="key" scontext=unconfined_u:unconfined_r:ssh_keygen_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=dir
type=AVC msg=audit(1323358944.706:324): avc:  denied  { create } for  pid=1578 comm="ssh-keygen" name="key" scontext=unconfined_u:unconfined_r:ssh_keygen_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file
type=AVC msg=audit(1323358944.706:324): avc:  denied  { write open } for  pid=1578 comm="ssh-keygen" name="key" dev=vda3 ino=2820 scontext=unconfined_u:unconfined_r:ssh_keygen_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file

Comment 6 Daniel Walsh 2011-12-08 20:04:33 UTC
If you remove the .ssh directory or fix its label, it will work.

restorecon -R -v ~/.ssh

Comment 7 Tomas Mraz 2011-12-08 20:58:06 UTC
No, the problem is that ssh_keygen_t should be allowed to write just anywhere in the user's home directory, not only into ssh_home_t.

Comment 8 Miroslav Grepl 2011-12-09 08:52:02 UTC
Petr,
I understand your point you run as unconfined SELinux user and you are confined. We needed to add this change because of CC. We made ssh_keygen_t domain as unconfined domain in the latest RHEL6.3 policy which should make this working.

The problem is we can not add a proper SELinux solution until we get file name transition into RHEL6.

Comment 9 Miroslav Grepl 2011-12-09 09:50:15 UTC
Petr,
could you test it with the latest policy?

Comment 11 Miroslav Grepl 2012-01-26 07:55:39 UTC
ssh-keygen now runs as unconfined domain in targeted policy by default.

Comment 14 errata-xmlrpc 2012-06-20 12:27:57 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2012-0780.html


Note You need to log in before you can comment on or make changes to this bug.