-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxssh
More file actions
executable file
·57 lines (48 loc) · 1.88 KB
/
xssh
File metadata and controls
executable file
·57 lines (48 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env bash
#
# ############################################################################
# Project: scripts (none)
# File...: xssh
# Created: Thursday, 2025/01/23 - 18:02:34
# Author.: fbnmtz, (fabiano.matoz@gmail.com)
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Last Modified: Tuesday, 2025/02/04 - 02:31:31
# Modified By..: @fbnmtz, (fabiano.matoz@gmail.com)
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Version: 1.0.2.89
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Description:
# >
# ############################################################################
# HISTORY:
#
source "$xSHELL_INIT"
use args colors
xrequirements ssh ssh-keyscan ssh-keygen cut
xarg --id -u,--user --var user+r --desc "login with <user>"
xarg --id -H,--host --var host+r --desc "<host> to connect "
xarg --id -k,--known --desc "show ssh known hosts"
xarg --id -r,--remove --var host+r --desc "remove <host> form known_hosts"
xrun --xrequire-one --xversionrc --xcolors "$@"
# -k/--known option: show knwon hosts
[ "$xarg" == "k" ] && { less ~/.ssh/known_hosts; exit 0; }
[ "$xarg" == "r" ] && { ssh-keygen -R "$host" -f ~/.ssh/known_hosts; exit 0; }
# Extrai o usuário e o IP do parâmetro
USER_IP=$1
if [ -n "$user" ] && [ -n "$host" ]; then
ssh_cmd="ssh $user@$host"
IP=$host
else
IP=$(echo "$USER_IP" | cut -d'@' -f2)
ssh_cmd="ssh $USER_IP"
fi
# Verifica se o host está online e adiciona o IP ao known_hosts
if ssh-keyscan -H "$IP" >> ~/.ssh/known_hosts; then
# Conecta via SSH
$ssh_cmd
# Remove o IP do known_hosts após encerrar a conexão SSH
ssh-keygen -R "$IP"
else
echo -e "${BGRED} Error! Host $IP unreachable. ${RESET}" >&2
exit 2
fi