Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 02bc8eb725 | |||
| d9e001cacf |
@@ -11,7 +11,7 @@ description: SSHRM project conventions
|
||||
- Prefer minimal, focused changes that do not alter the intent of the existing scripts, unless the script behavior is intentionally updated.
|
||||
- Maintain `.continue/rules/project.md` whenever project conventions or script behavior change.
|
||||
- `sshrm` is implemented as a small Bash script with helper functions, while preserving host and line-number removal behavior.
|
||||
- `sshrm` should print a short usage line, support `-h`/`--help`, fail clearly on missing or invalid line-number input, reject extra arguments, and may support a dedicated `--no-backup` option with a `known_hosts.sshrm.bak` backup file.
|
||||
- `sshrm` should print a short usage line, support `-h`/`--help`, fail clearly on missing or invalid line-number input, reject extra arguments, may support a dedicated `--no-backup` option with a `known_hosts.sshrm.bak` backup file, and now asks for confirmation before removal.
|
||||
|
||||
# Project identity
|
||||
- Main script: `sshrm`
|
||||
|
||||
@@ -5,12 +5,13 @@ Remove an entry from `~/.ssh/known_hosts` by host name or by line number.
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
sshrm [OPTION]... HOST|LINE
|
||||
sshrm [-h|--help] [--no-backup] host|line_number
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
- `-h`, `--help` Show help and exit.
|
||||
- `--no-backup` Skip creating `~/.ssh/known_hosts.sshrm.bak`.
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -26,10 +27,16 @@ Remove by line number:
|
||||
sshrm 12
|
||||
```
|
||||
|
||||
Remove without backup:
|
||||
|
||||
```bash
|
||||
sshrm --no-backup example.com
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- Line numbers must be positive integers.
|
||||
- Extra arguments are rejected.
|
||||
- The script asks for confirmation before removal.
|
||||
- The script edits `~/.ssh/known_hosts`.
|
||||
- Keep a backup if you need to recover entries.
|
||||
|
||||
|
||||
@@ -39,6 +39,20 @@ remove_host() {
|
||||
ssh-keygen -R "$1"
|
||||
}
|
||||
|
||||
confirm() {
|
||||
local prompt="$1"
|
||||
read -r -p "Remove ${prompt}? [y/N] " answer
|
||||
case "$answer" in
|
||||
y|Y|yes|YES)
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
error "cancelled."
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
if [ "${1-}" = "" ]; then
|
||||
error "missing argument."
|
||||
usage
|
||||
@@ -84,6 +98,10 @@ else
|
||||
HOST="$1"
|
||||
fi
|
||||
|
||||
if ! confirm "$HOST"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "${backup}" = true ]; then
|
||||
create_backup
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user