Bug 739989 - ssh-copy-id command should call restorecon if available on target machine
Summary: ssh-copy-id command should call restorecon if available on target machine
Alias: None
Product: Fedora
Classification: Fedora
Component: openssh
Version: 16
Hardware: Unspecified
OS: Unspecified
Target Milestone: ---
Assignee: Petr Lautrbach
QA Contact: Fedora Extras Quality Assurance
: 747527 752197 (view as bug list)
Depends On:
TreeView+ depends on / blocked
Reported: 2011-09-20 15:52 UTC by Jan Pokorný [poki]
Modified: 2018-12-03 17:22 UTC (History)
8 users (show)

Fixed In Version: openssh-5.8p2-22.fc16
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2011-11-26 23:10:04 UTC

Attachments (Terms of Use)

Description Jan Pokorný [poki] 2011-09-20 15:52:48 UTC
Using common ssh-keygen + ssh-copy-id way, I was not able to create
passwordless SSH connection between Fedora 16 (client) and RHEL 6 (server).
Entering password still worked well, but the desired behavior was different.

I tried many things trying to solve this, but to no avail.
Then I tried to apply ssh-keygen + ssh-copy-id sequence on another RHEL 6 box
and, to my big surprise, it started to work.

In the end, I discovered that the problem involves SELinux (standard enforcing
mode on each machine).  Diffing /usr/bin/ssh-copy-id file Fedora vs. RHEL,
Fedora's version apparently missing "restorecon" call.  Calling (e.g.)
"restorecon -R ~/.ssh" manually on the RHEL machine would help in my scenario,
still it is only a workaround that should be fixed with adding "restorecon"
call in a RHEL's way (testing that respective binary exists first).

Version-Release number of selected component (if applicable):
$ rpm -qf $(which ssh-copy-id)

Comment 1 Jan Pokorný [poki] 2011-09-20 17:38:08 UTC
This seems to be problem with Fedora 16 only (+ maybe rawhide).

Version in openssh-clients-5.6p1-34.fc15.1.x86_64 seems to be okay.

Comment 2 Stanislav Graf 2011-10-20 12:30:47 UTC
*** Bug 747527 has been marked as a duplicate of this bug. ***

Comment 3 Tomas Mraz 2011-10-20 13:00:23 UTC
Do you have latest SELinux policy installed?

It should no longer be necessary to call the restorecon.

Comment 4 Stanislav Graf 2011-10-20 19:09:59 UTC
Yes, latest selinux. Here is detailed scenario with selinux denying read to authorized keys:

[fedora16 ~]$ getenforce 
[fedora16 ~]$ rpm -qa | grep selinux
[fedora16 ~]$ ssh root@rhel6
[rhel6 ~]# yum update
No Packages marked for Update
[rhel6 ~]# rm -rf .ssh
[rhel6 ~]# logout
[fedora16 ~]$ ssh-copy-id root@rhel6
root@rhel6's password: 
[fedora16 ~]$ ssh root@rhel6
root@rhel6's password: 
[rhel6 ~]# ls -lZ .ssh/authorized_keys 
-rw-------. root root unconfined_u:object_r:admin_home_t:s0 .ssh/authorized_keys
[rhel6 ~]# rpm -qa | grep selinux
[rhel6 ~]# getenforce 
[rhel6 ~]# grep AVC /var/log/audit/audit.log
type=AVC msg=audit(1319137658.840:210): avc:  denied  { read } for  pid=2709 comm="sshd" name="authorized_keys" dev=vda1 ino=150423 scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:admin_home_t:s0 tclass=file

Comment 5 Tomas Mraz 2011-10-20 19:55:15 UTC
Ah, so you're doing ssh-copy-id from F16 to RHEL6 system. Then that makes sense that it is missing the restorecon call, because on RHEL6 it still has to be called. Perhaps the restorecon should not have been removed from the F16 ssh-copy-id yet.

Comment 8 Daniel Walsh 2011-11-15 14:07:59 UTC
You should be running the RHEL6.2 policy on the server.  Currently this is


Comment 9 Daniel Walsh 2011-11-15 14:09:23 UTC
sshd is in charge of creating this file/directory on the server.  The selinux-policy on the client, (the client does not even need to be running SELinux) does not matter.

The latest policy should do a file transition rule when sshd_t creates a directory in admin_home_t to ssh_home_t.

Comment 10 Stanislav Graf 2011-11-16 14:29:20 UTC
New user doesn't have this directory:
[rhel62 ~]# useradd --home-dir /home/testuser testuser
[rhel62 ~]# ls -ldZ /home/testuser/.ssh
ls: cannot access /home/testuser/.ssh: No such file or directory

And my reproduction scenario still doesn't work - using selinux-policy from comment 8 :

[fedora16 ~]$ getenforce
[fedora16 ~]$ rpm -q selinux-policy
[fedora16 ~]$ ssh root@rhel62
Last login: Wed Nov 16 15:16:06 2011 from fedora16
[rhel62 ~]# rpm -q selinux-policy
[rhel62 ~]# rm -rf .ssh
[rhel62 ~]# logout
Connection to rhel62 closed.
[fedora16 ~]$ ssh-copy-id root@rhel62
root@rhel62's password: 
Now try logging into the machine, with "ssh 'root@rhel62'", and check in:


to make sure we haven't added extra keys that you weren't expecting.

[fedora16 ~]$ ssh root@rhel62
root@rhel62's password: 
Last login: Wed Nov 16 15:16:55 2011 from fedora16
[rhel62 ~]# ls -lZ .ssh/authorized_keys
-rw-------. root root unconfined_u:object_r:admin_home_t:s0 .ssh/authorized_keys
[rhel62 ~]# getenforce 

Am I missing something?

Comment 11 Daniel Walsh 2011-11-16 21:53:28 UTC
Looks like we have a bug.

Comment 12 Daniel Walsh 2011-11-16 22:13:06 UTC
Jan when I do an ssh-copy-id what process creates the /root/.ssh directory? 

Does sshd do this or does it exec a second process?

Comment 13 Tomas Mraz 2011-11-18 07:31:52 UTC
It is done by a regular login shell executed from the sshd.

Comment 14 Daniel Walsh 2011-11-18 14:51:31 UTC
What command is executed?  So this is happening after pam_selinux and therefor the process is running as unconfined_t rather then sshd_t.  The polciy is handling sshd_t but can not handle unconfined_t or other users until Fedora 16.

If we executed the script without going through pam_selinux it would work.

Comment 15 Tomas Mraz 2011-11-18 17:02:29 UTC
(In reply to comment #14)
> If we executed the script without going through pam_selinux it would work.

Unfortunately this is impossible as this would require to have a special SSH protocol message for that and we cannot add it to the standard.

Comment 16 Daniel Walsh 2011-11-18 17:50:38 UTC
Tomas what program is it using to create and populate the directory?

Comment 17 Daniel Walsh 2011-11-18 19:30:32 UTC
Tomas, I have finally gotten a clue.  sh-copy-id should still have the restorecon within the code.  (I never new ssh-copy-id was a simple script).  Since you do not know what the platform you will be ssh-copy-id into.  Only ssh-copy-id onto a F16 box will work.  If you are on f16 and ssh-copy-id onto an older SELinux box, it will not create the .ssh directory with the correct label.

Comment 18 Fedora Update System 2011-11-23 18:48:04 UTC
openssh-5.8p2-22.fc16 has been submitted as an update for Fedora 16.

Comment 19 Fedora Update System 2011-11-25 02:29:23 UTC
Package openssh-5.8p2-22.fc16:
* should fix your issue,
* was pushed to the Fedora 16 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing openssh-5.8p2-22.fc16'
as soon as you are able to.
Please go to the following url:
then log in and leave karma (feedback).

Comment 20 Fedora Update System 2011-11-26 23:10:04 UTC
openssh-5.8p2-22.fc16 has been pushed to the Fedora 16 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 21 Daniel Walsh 2011-12-12 16:35:37 UTC
*** Bug 752197 has been marked as a duplicate of this bug. ***

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