Fleet logo
Menu An icon indicating that interacting with this button will open the navigation menu.
Fleet logo An 'X' icon indicating that this can be interacted with to close the navigation menu.

Solutions

a small chevron
Device management

Device management

Remotely manage, and protect laptops and mobile devices.

Orchestration

Orchestration

Automate tasks across devices, from app installs to scripts.

Software management

Software management

Inventory, patch, and manage installed software.

Extend Fleet

Extend Fleet

Integrate your favorite tools with Fleet.


Customers

a small chevron
Stripe + Fleet

Stripe + Fleet

Stripe consolidates multiple tools with Fleet.

Foursquare + Fleet

Foursquare + Fleet

Foursquare quickly migrates to Fleet for device management.

What people are saying

What people are saying

Stories from the Fleet community.


Pricing

More

a small chevron
Docs

Docs

Guides

Guides

Support

Support

News

News

Get your license

Get your license

The handbook

The handbook

Fleet @ Meow Wolf

Kick off JNUC with Fleet at Meow Wolf Denver's Convergence Station.

Join us
Get a demo Try it yourself
Solutions A small chevron
Device management

Device management

Remotely manage, and protect laptops and mobile devices.

Orchestration

Orchestration

Automate tasks across devices, from app installs to scripts.

Software management

Software management

Inventory, patch, and manage installed software.

Extend Fleet

Extend Fleet

Integrate your favorite tools with Fleet.

Customers A small chevron
Stripe + Fleet

Stripe + Fleet

Stripe consolidates multiple tools with Fleet.

Foursquare + Fleet

Foursquare + Fleet

Foursquare quickly migrates to Fleet for device management.

What people are saying

What people are saying

Stories from the Fleet community.

Pricing
More A small chevron
Docs

Docs

Guides

Guides

Support

Support

News

News

Get your license

Get your license

The handbook

The handbook

Fleet @ Meow Wolf

Kick off JNUC with Fleet at Meow Wolf Denver's Convergence Station.

Join us
Try it yourself Get a demo
Queries/
Get unencrypted SSH keys for domain-joined accounts

Get unencrypted SSH keys for domain-joined accounts

Contributor's GitHub profile picture

Ahmed Elshaer

Identify SSH keys created without a passphrase which can be used in Lateral Movement (MITRE. TA0008)

To learn more about queries, check this guide.

Query PowerShellNEW BashNEW
SELECT uid, username, description, path, encrypted FROM users CROSS JOIN user_ssh_keys using (uid) WHERE encrypted=0 and username in (SELECT distinct(username) FROM last);
$lastOutput = & last
$lastUsernames = $lastOutput | ForEach-Object {
    if ($_ -match '^\s*(\S+)') { $matches[1] }
} | Select-Object -Unique

$passwdFile = "/etc/passwd"
if (Test-Path $passwdFile) {
    $lines = Get-Content $passwdFile
    foreach ($line in $lines) {
        # /etc/passwd format: username:password:UID:GID:GECOS:home_directory:shell
        $fields = $line -split ":"
        if ($fields.Length -ge 7) {
            $username = $fields[0]
            $uid = $fields[2]
            $description = $fields[4]
            $homeDir = $fields[5]

            if ($lastUsernames -contains $username) {
                # Assume the user's SSH authorized_keys file is in .ssh/authorized_keys in their home directory
                $sshKeyPath = Join-Path $homeDir ".ssh/authorized_keys"
                if (Test-Path $sshKeyPath) {
                    $keyLines = Get-Content $sshKeyPath
                    foreach ($keyLine in $keyLines) {
                        if ([string]::IsNullOrWhiteSpace($keyLine)) {
                            continue
                        }
                        # Determine if the key is encrypted by looking for the keyword "ENCRYPTED"
                        $encrypted = if ($keyLine -match "ENCRYPTED") { 1 } else { 0 }
                        if ($encrypted -eq 0) {
                            $result = [PSCustomObject]@{
                                uid         = $uid
                                username    = $username
                                description = $description
                                path        = $sshKeyPath
                                encrypted   = $encrypted
                            }
                            Write-Output $result
                        }
                    }
                }
            }
        }
    }
}
printf "uid,username,description,path,encrypted\n"; for u in $(last | awk '{print $1}' | grep -vE '^(wtmp|reboot)$' | sort -u); do [ -d "/Users/$u/.ssh" ] && for f in $(find "/Users/$u/.ssh" -type f -name "authorized_keys*" 2>/dev/null); do uid=$(id -u "$u"); desc=$(dscl . -read /Users/"$u" RealName 2>/dev/null | cut -d: -f2- | sed 's/^ //'); echo "$uid,$u,$desc,$f,0"; done; done
An icon indicating that this section has important information

PowerShell commands are currently work in progress, contributions welcome.

An icon indicating that this section has important information

Bash commands for macOS are currently work in progress, contributions welcome.

Platform

macOSApple

WindowsWindows

LinuxLinux

ChromeOSChromeOS

Suggest an editEdit Talk to an engineerGet a demo
Fleet logo
Multi platform Device management Orchestration Software management Integrations Pricing
Documentation Support Docs API Release notes Get your license
Company About News Jobs Logos/artwork Why open source?
ISO 27001 coming soon a small checkmarkSOC2 Type 2 Creative Commons Licence CC BY-SA 4.0
© 2025 Fleet Inc. Privacy
Slack logo GitHub logo LinkedIn logo X (Twitter) logo Youtube logo Mastadon logo
Tried Fleet yet?

Get started with Fleet

Start
continue
×