Sponsored Content
Full Discussion: Automating ssh connection
Top Forums Shell Programming and Scripting Automating ssh connection Post 303005185 by developy on Saturday 14th of October 2017 10:04:19 PM
Old 10-14-2017
Network Automating ssh connection

I want to create a script for the ssh connection that handles any input. Be it IP or DNS.
And instead of typing in giant commands, I'd like to downplay it and treat it.

I imagined the following command:

i machine
or
i machine.exemple.com.fr
or
i 111.222.333.4444

Login attempts should be made with devops, or with matheus.

I do not know much about shell script I'm reading a few hours and working on the script below.
Can you help me?
Thank you.

> /bin/i && chmod +x /bin/i && vi /bin/i
bash /bin/i

Code:
#!/bin/bash

if [ "$1" == "" ]
then
clear
echo "how to use:"
echo "i 111.222.333.444"
echo "i name"
echo "i name.exemple.com.fr"
echo ""
fi

#verifying that the input is a valid ip
if [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
      clear
      echo "Success! Accessing $1 with devops"
      ssh devops@$1
 elif
      clear
      echo "Oops! Could not access with devops, trying to access as matheus"
      ssh -i /home/devops/.ssh/matheus_rsa matheus@$1
else
      clear
      echo "Could not connect! Here's some information to access the provider platform."
      whois $1 | grep -E "mnt-by|OrgName|nserver"
      getent hosts $1
fi

#-f If you have text
if [ -f $1 ]; then
      clear
      echo "Success! Accessing $1 with devops"
      ssh devops@$1.exemple.com.fr
  elif
      clear
      echo "[1] Trying to connect..."
      ssh devops@$1
  elif
      clear
      echo "Oops! Could not access with devops, trying to access as matheus"
      ssh -i /home/devops/.ssh/matheus_rsa matheus@$1.exemple.com.fr
  elif
      clear
      echo "[2] Trying to connect..."
      ssh -i /home/devops/.ssh/matheus_rsa matheus@$1
else
      echo "Could not connect! Here's some information to access the provider platform."
      whois $1 | grep -E "mnt-by|OrgName|nserver"
      getent hosts $1
fi


Last edited by developy; 10-16-2017 at 10:44 PM..
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

ssh connection

pls how do i connect to my freebsd server via ssh from a windows client?? I have sshd running on d freebsd server. (9 Replies)
Discussion started by: lealyz
9 Replies

2. UNIX for Dummies Questions & Answers

ssh connection

Hi @ all! I've a problem with a ssh-connection. I want to establish a ssh-connection between an AIX-System and an SunOS-System without a password. The Users are different one's. Command : user1@server1 /home/user1 > ssh user2@server2 Is it possible? Greetings olli-h (1 Reply)
Discussion started by: olli-h
1 Replies

3. Shell Programming and Scripting

automating ssh session with password

Hi Can anyone help me in automate a ssh session with password using shell script (7 Replies)
Discussion started by: raghav288
7 Replies

4. Shell Programming and Scripting

Automating file transfer between two SSH enabled server.

Hi Experts, Few more words to the title, both the servers are ssh enabled but I have read only access to the second server, so I cannot automate SFTP process using RSA/DSA keys. I am using Control M to trigger the script and do not want any manual intervention to enter the password to complete... (4 Replies)
Discussion started by: nchourasiya
4 Replies

5. Red Hat

Ssh connection

hi, I have ssh connection between two servers for a functional Id for SFTP purpose. I aim is to setup this for is only work when below command is used by a .ksh script. ssh userid@servername:/directory Unfortunately users who have access to functional id are manually using above command... (2 Replies)
Discussion started by: maddy26615
2 Replies

6. UNIX for Advanced & Expert Users

How keep running a program n an another computer via a connection ssh when the connection is closed?

Hi everybody, I am running a program on a supercomputer via my personal computer through a ssh connection. My program take more than a day to run, so when I left work with my PC I stop the connection with the supercomputer and the program stop. I am wondering if someone know how I can manage... (2 Replies)
Discussion started by: TomTomGre
2 Replies

7. UNIX for Advanced & Expert Users

Connection-less using ssh

Hi! I know its a recurring problem, but I am failing to sort this out, I have two servers ( A and B), in which I am able to connect without having to put password from server B to server A, but the connect from server A to server B. takes 7 minutes to establish??? on Server A, I have the... (7 Replies)
Discussion started by: fretagi
7 Replies

8. BSD

Connection SSH to remote by ssh

Hello guys! I am setting up a script to access a unix remote server. My problem is that when I put the ssh line "my host", the script does not wait for the server response asking for the password to execute the line in which I put the password, that is, I need to put a form in which script has a... (1 Reply)
Discussion started by: aroucasp
1 Replies

9. UNIX for Beginners Questions & Answers

Ssh script to validate ssh connection to multiple serves with status

Hi, I want to validate ssh connection one after one for multiple servers..... password less keys already setup but now i want to validate if ssh is working fine or not... I have .sh script like below and i have servers.txt contains all the list of servers #/bin/bash for host in $(cat... (3 Replies)
Discussion started by: sreeram4
3 Replies
SSH-KEYSIGN(8)						    BSD System Manager's Manual 					    SSH-KEYSIGN(8)

NAME
ssh-keysign -- ssh helper program for host-based authentication SYNOPSIS
ssh-keysign DESCRIPTION
ssh-keysign is used by ssh(1) to access the local host keys and generate the digital signature required during host-based authentication with SSH protocol version 2. ssh-keysign is disabled by default and can only be enabled in the global client configuration file /etc/ssh/ssh_config by setting EnableSSHKeysign to ``yes''. ssh-keysign is not intended to be invoked by the user, but from ssh(1). See ssh(1) and sshd(8) for more information about host-based authen- tication. FILES
/etc/ssh/ssh_config Controls whether ssh-keysign is enabled. /etc/ssh/ssh_host_dsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_rsa_key These files contain the private parts of the host keys used to generate the digital signature. They should be owned by root, read- able only by root, and not accessible to others. Since they are readable only by root, ssh-keysign must be set-uid root if host- based authentication is used. /etc/ssh/ssh_host_dsa_key-cert.pub /etc/ssh/ssh_host_ecdsa_key-cert.pub /etc/ssh/ssh_host_rsa_key-cert.pub If these files exist they are assumed to contain public certificate information corresponding with the private keys above. SEE ALSO
ssh(1), ssh-keygen(1), ssh_config(5), sshd(8) HISTORY
ssh-keysign first appeared in OpenBSD 3.2. AUTHORS
Markus Friedl <markus@openbsd.org> BSD
August 31, 2010 BSD
All times are GMT -4. The time now is 03:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy