You are browsing a read-only backup copy of Wikitech. The live site can be found at wikitech.wikimedia.org

Difference between revisions of "Help:SSH Fingerprints"

From Wikitech-static
Jump to navigation Jump to search
imported>Krinkle
(Doesn't do anything. Also, output of Special:PrefixIndex is a table, which doesn't work well inside <ul>)
 
imported>Alex Monk
(example script to generate these pages)
Line 1: Line 1:
{{Special:PrefixIndex/{{FULLPAGENAME}}/}}
{{Special:PrefixIndex/{{FULLPAGENAME}}/}}
To find this information, locally you can just run this:
<syntaxhighlight lang="bash">for file in /etc/ssh/*_key.pub; do ssh-keygen -lf $file; done</syntaxhighlight>
Remotely (and to format it for these pages), something like this should work:
<syntaxhighlight lang="python3">#!/usr/bin/python3
import sys
if len(sys.argv) == 0:
print('Must specify hostname')
sys.exit(0)
hostname = sys.argv[1]
port = 22
if len(sys.argv) > 2:
port = sys.argv[2]
import subprocess, tempfile
with tempfile.NamedTemporaryFile() as tf:
keyscanCommand = 'ssh-keyscan', '-t', 'rsa,ecdsa,ed25519', '-p', str(port), hostname
subprocess.call(keyscanCommand, stdout = tf.file, stderr = open('/dev/null'))
keygenProcess = subprocess.Popen(['ssh-keygen', '-l', '-f', tf.name], stdout = subprocess.PIPE)
stdout, stderr = keygenProcess.communicate()
for line in stdout.decode('ascii').splitlines():
bitlen, fingerprint, hostname, type = line.split(' ')
print(type[1:-1] + ':  <code>' + fingerprint + '</code>\n')</syntaxhighlight>

Revision as of 20:05, 10 October 2015

To find this information, locally you can just run this:

for file in /etc/ssh/*_key.pub; do ssh-keygen -lf $file; done

Remotely (and to format it for these pages), something like this should work:

#!/usr/bin/python3
import sys
if len(sys.argv) == 0:
	print('Must specify hostname')
	sys.exit(0)
hostname = sys.argv[1]
port = 22
if len(sys.argv) > 2:
	port = sys.argv[2]

import subprocess, tempfile
with tempfile.NamedTemporaryFile() as tf:
	keyscanCommand = 'ssh-keyscan', '-t', 'rsa,ecdsa,ed25519', '-p', str(port), hostname
	subprocess.call(keyscanCommand, stdout = tf.file, stderr = open('/dev/null'))
	keygenProcess = subprocess.Popen(['ssh-keygen', '-l', '-f', tf.name], stdout = subprocess.PIPE)
	stdout, stderr = keygenProcess.communicate()
	for line in stdout.decode('ascii').splitlines():
		bitlen, fingerprint, hostname, type = line.split(' ')
		print(type[1:-1] + ':  <code>' + fingerprint + '</code>\n')