2
1
I'm running the following command on a fairly standard Ubuntu 11.04 installation running under vSphere:
sudo cat /home/*/.ssh/authorized_keys
Basically, I am using puppet for ssh key management and wanted to ensure the keys were present. What is unusual about this simple command is that the keys are only shown for two users (the first and third user created on the user if that is relevant) when the * should catch something like 7 or 8 users' homes.
The intriguing part is that, if I run
sudo cat /home/user.name/.ssh/authorized_keys
where user.name is the name of a random user (not one of the two that already show), not only do I get the correct output from cat, but the next time I run
sudo cat /home/*/.ssh/authorized_keys
the output shows 3 key files! Two files for the two users previously shown and a third file that is the user whose key file I just manually looked at.
I can continue to play this "game", and each time I manually specify a user and then run the * command, that previously viewed user shows up in the globbed output. To me, this is unusual behavior, especially for a bog-standard Ubuntu image. Is there something I am missing? Special properties of * expansion or cat?
Edit: Forgot to mention that this behavior "resets" if I leave the ssh session to the server. By that I mean that I can logout and log back in via SSH, and I am back to the starting conditions (only two user accounts are shown with *).
Your explanation of the reason for the strange globbing behavior is brilliant, +1, but I'm not entirely convinced. Why does the
sudo cat /home/user.name/.ssh/authorized_keyscommand have the lasting side effect of affecting the output of subsequent commands containing the glob, when the glob command isn't able to see the contents prior to that direct cat? Is it because the shell caches the files it sees in there? – allquixotic – 2012-07-13T02:11:38.5071Okay, the 1st solution is within my knowledge of find. And I was about to ask you why the one user would show up (using *) while others wouldn't but I just discovered that the ssh folder for that user is 755 as opposed to the others that are 700. – Richard Martinez – 2012-07-13T02:14:34.457
Add.: It just seems odd to me that
look at some files that only root can see;followed bylook at files that my user can seeresults in the latter command "knowing" about the directory structure by virtue of the former command successfully stating that directory. Especially since the "direct" (non-globbed) method doesn't involve ANY shell expansion whatsoever, so the shell is not finding that directory; thecatcommand is! Within a sudo instance at that!!! – allquixotic – 2012-07-13T02:15:21.507I can't explain the lasting side effect, although since it 'resets' when you log off, it might be related to the sudo window. That period of time during which sudo will let you do things before the permissions run out again. Usually like 5 minutes or 15 minutes from the LAST valid sudo you executed. – lornix – 2012-07-13T02:15:50.807
Based on Richard's explanation of the permissions, now I understand why the heisenbug with only some of the users displaying. This solves the mystery so we don't have to go wondering about bash examining the
fstat()syscalls of its child processes to learn about directories it's aware of. o_O – allquixotic – 2012-07-13T02:17:28.2171Exactly. My answer did involve permissions, I just beat around the bush the long way... Thanks for the help @allquixotic – lornix – 2012-07-13T02:19:00.770
Help?!?! I learned something! That's the best part of participating in this discussion! :) Thank YOU! – allquixotic – 2012-07-13T02:21:35.957
Okay so the permission issue explained why I always get the one additional user. And I just tested the * command with a sudo -K (to reset the timestamp) and that is indeed the solution for the second part. The "lasting" side-effect is due to the sudo time window. Interesting info, thanks for the help! – Richard Martinez – 2012-07-13T02:21:47.913