Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9342888
ssh_keys_users.rb
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
ssh_keys_users.rb
View Options
# SPDX-License-Identifier: GPL-3
# From https://gitlab.com/shared-puppet-modules-group/sshd/ @ c887bf09
require
'etc'
# this fact will iterate over all the known users (as defined by the
# Etc module) and look in their .ssh directory for public keys. the
# public keys are exported in a user => [keys] hash, where keys are
# stored in the array without distinction of type
Facter
.
add
(
:ssh_keys_users
)
do
setcode
do
keys_hash
=
{}
Etc
.
passwd
{
|
user
|
keys
=
{}
Dir
.
glob
(
File
.
join
(
user
.
dir
,
'.ssh'
,
'*.pub'
))
.
each
{
|
filepath
|
if
FileTest
.
file?
(
filepath
)
regex
=
%r{^ssh-(\S+) (\S+)\s?(.+)?$}
begin
line
=
File
.
open
(
filepath
)
.
read
.
chomp
if
(
match
=
regex
.
match
(
line
))
keys
[
File
.
basename
(
filepath
)
]
=
{
'type'
=>
match
[
1
]
,
'key'
=>
match
[
2
]
,
'comment'
=>
match
[
3
]
}
end
rescue
puts
"cannot read user SSH key: "
+
user
.
name
end
end
}
keys_hash
[
user
.
name
]
=
keys
if
not
keys
.
empty?
}
keys_hash
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Fri, Jul 4, 1:05 PM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3239604
Attached To
rSPSITE puppet-swh-site
Event Timeline
Log In to Comment