Skip to content

ISC-HEI/ssh-pubkey-finder

Repository files navigation

SSH Pubkey Finder

OS Language GitHub Release Release Date Last Commit

SSH Pubkey Finder is a Bash script that allows you to retrieve all the authorized SSH public keys on a Linux system.

Table of Contents

Features

  • Retrieves all users on the system.
  • Lists authorized SSH public keys for each user.
  • Allows specifying a user’s group.

Installation

Installing from GitHub

Clone the GitHub repository:

git clone https://github.com/ISC-HEI/ssh-pubkey-finder.git
cd ssh-pubkey-finder

Installing via apt (for Debian/Ubuntu)

You can add the official repository and install the package directly:

  1. Add the repository to your system:
echo "deb [trusted=yes] https://apt.chezmoicamarche.ch/ssh-pubkey-finder/repo stable main" | sudo tee /etc/apt/sources.list.d/ssh-pubkey-finder.list
  1. Update your package lists and install the package:
sudo apt update
sudo apt install ssh-pubkey-finder
  1. Run the script:
ssh-pubkey-finder -v
# Output: 0.3.0

Note: Installing via apt makes the script available system-wide, so you don’t need to be in the repository folder to run it.

Installation via Snap

To install this script using Snap, you can run:

./build-snap.sh

This will create a .snap file in the dist folder. Then install it like that:

sudo snap install ./dist/ssh-pubkey-finder_0.3.0_amd64.snap --classic --dangerous

If you want to publish this script, you can check the corresponding README.md

Script Execution

Run the script using the following command:

If the script is installed system-wide:

ssh-pubkey-finder

If running directly from the cloned repository:

# Make sure the script is executable (normally it is)
chmod +x ssh-pubkeys-finder

# Execute the script
./ssh-pubkeys-finder

Arguments

Argument Description Params
-h Show help X
-v Show the current version X
-u USER Check only for the specified user USER: the user to check

Example

Here you can see an example of output with no argument:

admin@mypc:~/$ ./ssh-pubkey-finder
Permission denied, root may have some public keys
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICBeVf+bmAsL6O0li173PA8dw4qSWwU1v3WegXGB26IV adrien
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOgJnqfqwBihTBLfBn0+SEr0W1oWz13mUFFZ56XSYoC8 adrien
admin@mypc:~/$ sudo ./ssh-pubkey-finder
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICBeVf+bmAsL6O0li173PA8dw4qSWwU1v3WegXGB26IV adrien, local
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOgJnqfqwBihTBLfBn0+SEr0W1oWz13mUFFZ56XSYoC8 adrien

Here you can see an example with the specified user

admin@mypc:~/$ sudo ./ssh-pubkey-finder -u adrien
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICBeVf+bmAsL6O0li173PA8dw4qSWwU1v3WegXGB26IV adrien
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOgJnqfqwBihTBLfBn0+SEr0W1oWz13mUFFZ56XSYoC8 adrien

License

The current License is Apache version 2.0, you can see it in the LICENSE file.

About

This script retrieves all users from a device and, for each user, gets the authorized public SSH key.

Topics

Resources

License

Stars

Watchers

Forks