openssl s_client -showcerts -connect HOST:PORT </dev/null 2>/dev/null | sed -n -e '/-.BEGIN/,/-.END/ p'
Replace `HOST` with hostname or IP of server. Replace `PORT` accordingly (e. g. 1965 for gemini, 443 for web or 993 for mail). Append e.g. `> out.pem` to save as file.