Before you begin
- Bash 4+ on Linux.
- Required tools: stat, find. Requires GNU stat and find. ACL and network-filesystem policies are outside this report.
Set up your example
- Save as linux-ssh-file-permissions.sh.
- Open a terminal in its folder.
- Run bash "linux-ssh-file-permissions.sh" --help; invoking bash does not require executable permission.
This recipe uses your own local input or creates its own example output. Follow the setup steps below.
Download the ZIP, extract it, and open a terminal inside the extracted folder. The source file is linux-ssh-file-permissions.sh.
Run the script
bash "linux-ssh-file-permissions.sh"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
The directory may show 700 and a private key 600; no key content is printed.
The complete script
#!/usr/bin/env bash
set -euo pipefail
if [[ ${1:-} == --help || ${1:-} == -h ]]; then
cat <<\SCRIPTAGE_HELP
Inspect SSH file modes
Usage: bash linux-ssh-file-permissions.sh [SSH_DIRECTORY]
Display owners and permission modes for a selected SSH directory without printing key contents.
Read-only local report.
SCRIPTAGE_HELP
exit 0
fi
for tool in stat find; do
command -v "$tool" >/dev/null 2>&1 || { printf 'Missing required tool: %s\n' "$tool" >&2; exit 1; }
done
root=${1:-"$HOME/.ssh"}
[[ -d "$root" ]] || { printf 'Not found: %s\n' "$root" >&2; exit 1; }
stat --printf='%a %U:%G %n\n' -- "$root"
find "$root" -mindepth 1 -maxdepth 1 -type f -exec stat --printf='%a %U:%G %n\n' -- {} +
Open source as plain text · Download source and sample files
How it works
- Display owners and permission modes for a selected SSH directory without printing key contents.
- Required commands are checked before collecting the report.
- The output is a local snapshot; restricted permissions or unavailable kernel data can limit visibility.
Make it your own
Adjust scope
Pass a different SSH directory as the first argument; compare modes with your SSH policy before separate changes.
Save a snapshot
Redirect to a new unused .txt filename for comparison. Shell redirection can overwrite files; choose a fresh name.
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
A required tool is missing.
Install its package through your normal distribution maintenance process. This script does not install anything.
The report is empty or permission is denied.
Requires GNU stat and find. ACL and network-filesystem policies are outside this report.
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.