[LINUX] Create ssh-config and create ssh-config host list acquisition command

Simplification of SSH command

To make an ssh connection, execute the following command.

ssh -i Certificate path username@IP address

If you use it often, you can use config and execute it with the following command.

ssh host name

Create config file

Storage destination → ~ / .ssh / config The contents of the file are as follows.

config


Host DataLamda_Outer
HostName IP or DNS
User Connected user
Port Connection destination port
IdentityFile key file

If you don't know the host of config

As shown below, I created a shell that can get a list of connected hosts.

sshls


#!/bin/sh

SSH_CONFIG=$HOME/.ssh/config

echo "known hosts:"

if test -e $SSH_CONFIG; then
    for i in `grep "^Host " $SSH_CONFIG | sed s/"^Host "//`
    do
        echo "  ${i};"
    done
else
    echo "nothing ssh-lsconfig file"
fi

There are three steps to make it a command.

  1. Grant permissions to the file → chmod 755 sshls
  2. Alias registration → bash _profile for bash people, ʻalias sshls'~ / bin / sshls'` in fish.config for fish people
  3. Restart the console

The execution result looks like this

$sshls Sat 6/13 23:08:17 2020
known hosts:
  DataLamda_Outer;

Recommended Posts

Create ssh-config and create ssh-config host list acquisition command
Create and list Django models
Linux command list
list and numpy
Create Django Todo list
[Python] Create a date and time list for a specified period
Python: Create a dictionary from a list of keys and values