#!/usr/bin/php
<?php

$files = array_merge(['/root/.ssh/authorized_keys'], glob('/home/*/.ssh/authorized_keys'));

foreach ($files as $file) {
	if (!file_exists($file)) continue;
	$lines = file($file);
	echo "$file:\n";
	foreach ($lines as $line) {
		// https://serverfault.com/questions/888281/what-is-the-sha256-that-comes-on-the-sshd-entry-in-auth-log
		$line = trim($line);
		if ($line == '') continue;
		if (substr($line,0,1) == '#') continue;
		$line = str_replace("\t", ' ', $line);
		$line = trim(preg_replace('/^ssh-rsa/', '', $line));
		$data = trim(explode(' ', $line, 2)[0]);
		$user = trim(explode(' ', $line, 2)[1]);
		echo "\tSHA256: " . base64_encode(hash('sha256',base64_decode($data),true)) . " $user\n";
	}
}

