PythonIntermediate · Windows, macOS, or Linux; Python 3.12+

Review SSH client option risks

Flag selected SSH client options in a local configuration without connecting to any host.

Before you begin

  • Python 3.12 or later.
  • Read access to the selected inputs.
What this script changesRead-only local report. No permissions, accounts, configuration, or input files are changed. Review filenames and metadata before sharing.

Set up your example

  1. Save as security-ssh-config-review.py.
  2. Open a terminal in its folder.
  3. Run python "security-ssh-config-review.py" --help and prepare the listed input files.

Sample files in this download:

  • ssh_config

Download the ZIP, extract it, and open a terminal inside the extracted folder. The source file is security-ssh-config-review.py.

Run the script

Run command
python "security-ssh-config-review.py" "ssh_config"

If your system uses python3 instead of python, use that command for Python examples. Keep paths containing spaces in quotes. Required inputs and optional settings are described in the code and setup steps.

What to expect

ForwardAgent yes is listed by line; no SSH connection is attempted.

The complete script

security-ssh-config-review.py
#!/usr/bin/env python3
"""Flag selected SSH client options in a local configuration without connecting to any host."""
import argparse
import sys
import json
from pathlib import Path
import shlex

def main():
    parser = argparse.ArgumentParser(description='Flag selected SSH client options in a local configuration without connecting to any host.')
    parser.add_argument('config',type=Path)
    args = parser.parse_args()
    risky={'stricthostkeychecking':{'no','off','false'},'forwardagent':{'yes','true','on'},'permitlocalcommand':{'yes','true','on'}}
    for number,line in enumerate(args.config.read_text(encoding='utf-8').splitlines(),1):
        try:parts=shlex.split(line,comments=True)
        except ValueError:print(json.dumps({'line':number,'issue':'parse error'}));continue
        if not parts:continue
        if '=' in parts[0]:parts=parts[0].split('=',1)+parts[1:]
        if len(parts)>1 and parts[0].lower() in risky and parts[1].lower() in risky[parts[0].lower()]:print(json.dumps({'line':number,'option':parts[0],'issue':'review option within its Host/Match context'}))

if __name__ == '__main__':
    try:
        main()
    except (OSError, ValueError, RuntimeError) as exc:
        print(f'Error: {exc}', file=sys.stderr)
        sys.exit(1)

Open source as plain text · Download source and sample files

How it works

  1. Flag selected SSH client options in a local configuration without connecting to any host.
  2. Arguments are explicit and expected input errors produce a message with a nonzero exit code.
  3. Results reflect your selected local data or the specific endpoint you choose; the example illustrates the result shape.

Make it your own

Adapt the task

Change risky for your policy. This simple parser does not evaluate Include files, Host matching, or option precedence.

Adjust presentation

Edit final print statements or json.dumps indentation to adjust the report layout. Keep input validation and exclusive-create file modes intact.

Change one setting at a time, run it again on sample data, and compare the output. The customization guide walks through this process.

If something goes wrong

An input or dependency is unavailable.

Check the path, quote paths with spaces, and use --help to inspect required arguments.

Actual results differ from the example.

Inputs and system state determine values. Review each finding in context; a report is not proof of system health or a complete security assessment.

Reference & next steps

These official references explain the underlying tools. The Scriptage example and guide are original instructional content. See verification notes for what has been checked and the limits of those checks.

Copies a template for your own notes. It does not send anything.