Skip to content

SSH Functions

🛠️ Tools · ⬅ Top


sshKnownHostAdd

Adds the host to the ~/.known_hosts if it is not

Usage

sshKnownHostAdd [ host0 ]

Adds the host to the ~/.known_hosts if it is not found in it already

Side effects: 1. ~/.ssh may be created if it does not exist 1. ~/.ssh mode is set to 0700 (read/write/execute user) 1. ~/.ssh/known_hosts is created if it does not exist 1. ~/.ssh/known_hosts mode is set to 0600 (read/write user) 1. ~./.ssh/known_hosts is possibly modified (appended)

If this function fails then ~/.ssh/known_hosts may be modified for any hosts which did not fail

Return Code: 1 - Environment errors Return Code: 0 - All hosts exist in or were successfully added to the known hosts file

If no arguments are passed, the default behavior is to set up the ~/.ssh directory and create the known hosts file.

Arguments

  • host0 - String. Optional. One ore more hosts to add to the known hosts file

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

sshSetup

Set up SSH for a user with ID and backup

Usage

sshSetup [ --force ] [ server ... ]

Set up SSH for a user with ID and backup keys in ~/.ssh

Create a key for a user for SSH authentication to other servers.

Add .ssh key for current user

You will need the password for this server for the current user.

Arguments

  • --force - Flag. Optional. Force the program to create a new key if one exists
  • server - String. Required. Servers to connect to to set up authorization

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Requires

userRecordHome catchEnvironment throwEnvironment

sshKnownHostRemove

Adds the host to the ~/.known_hosts if it is not

Usage

sshKnownHostRemove [ host0 ]

Adds the host to the ~/.known_hosts if it is not found in it already

Side effects: 1. ~/.ssh may be created if it does not exist 1. ~/.ssh mode is set to 0700 (read/write/execute user) 1. ~/.ssh/known_hosts is created if it does not exist 1. ~/.ssh/known_hosts mode is set to 0600 (read/write user) 1. ~./.ssh/known_hosts is possibly modified (appended)

If this function fails then ~/.ssh/known_hosts may be modified for any hosts which did not fail

Return Code: 1 - Environment errors Return Code: 0 - All hosts exist in or were successfully added to the known hosts file

If no arguments are passed, the default behavior is to set up the ~/.ssh directory and create the known hosts file.

Arguments

  • host0 ... - String. Optional. One ore more hosts to add to the known hosts file --skip-backup |- --no-backup - Flag. Optional. Skip the file backup as name.$(todayDate)
  • --verbose - Flag. Optional. Be verbose.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

sshKnownHostsFile

!/usr/bin/env bash

Usage

sshKnownHostsFile

!/usr/bin/env bash

git tools, lame attempts have been made to have each function start with git.

Copyright © 2026 Market Acumen, Inc.

Arguments

  • none

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error