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-COPY-ID(1)						      General Commands Manual						    SSH-COPY-ID(1)

NAME
ssh-copy-id - install your public key in a remote machine's authorized_keys SYNOPSIS
ssh-copy-id [-i [identity_file]] [user@]machine DESCRIPTION
ssh-copy-id is a script that uses ssh to log into a remote machine and append the indicated identity file to that machine's ~/.ssh/autho- rized_keys file. If the -i option is given then the identity file (defaults to ~/.ssh/id_rsa.pub) is used, regardless of whether there are any keys in your ssh-agent. Otherwise, if this: ssh-add -L provides any output, it uses that in preference to the identity file. If the -i option is used, or the ssh-add produced no output, then it uses the contents of the identity file. Once it has one or more fin- gerprints (by whatever means) it uses ssh to append them to ~/.ssh/authorized_keys on the remote machine (creating the file, and directory, if necessary.) NOTES
This program does not modify the permissions of any pre-existing files or directories. Therefore, if the remote sshd has StrictModes set in its configuration, then the user's home, ~/.ssh folder, and ~/.ssh/authorized_keys file may need to have group writability disabled manu- ally, e.g. via chmod go-w ~ ~/.ssh ~/.ssh/authorized_keys on the remote machine. SEE ALSO
ssh(1), ssh-agent(1), sshd(8) OpenSSH 14 November 1999 SSH-COPY-ID(1)
All times are GMT -4. The time now is 05:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy