OpenSSL/SSH

From wiki
Revision as of 13:50, 4 May 2025 by Hdridder (talk | contribs)
Jump to navigation Jump to search
openssl rsa -text -noout -in id_rsa
Print out key attributes (o.a. key length)
openssl s_client -showcerts -connect <system>:<port>
Get the certificates available and test connectivity
openssl x509 -outform der -in <pemfile> -out <filename>.der -text
Convert to DER format.
ssh-keygen -t ed25519
Create a keypair (accept all defaults, put a password if you want)
ssh-keygen -y -f <privatkeyfile>
Print the public key for the private key in <privatkeyfile>
ssh user@target
SSH into target system as user, if user is omitted the current username is used
ssh -vvv user@target
Be very verbose with debug information
ssh -i keyfile user@target
Use the key in keyfile to connect


Certificates

For web-servers you can buy a certificate of get one for free from letsencrypt.

If for some reason you want to have a self signed certificate you can use this

openssl genrsa  -out server.key 4096
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.pem

Now copy the server.pem and the server.key to the location for your web server.

I used this to make a default server that catches all traffic to port 80 and to 443 to redirect it. If you don't do this nginx will serve the first server it finds in it's configuration. The certificate has no content except for the CN being 'fake'

Default server configuration
#
server {
	listen 80 default_server;
	listen [::]:80 default_server;

	# SSL configuration
	#
	listen 443 ssl default_server;
	listen [::]:443 ssl default_server;
    ssl_certificate      /var/www/tmp/fake.pem;
    ssl_certificate_key  /var/www/tmp/fake.key;

    root /var/www/html;

	# Add index.php to the list if you are using PHP
	index index.html index.htm index.nginx-debian.html;

	server_name _;

	location / {
		try_files $uri $uri/ =404;
	}

}