Solved Using RSA Key to SSH

August 21, 2017 at 06:04:54
Specs: Linux virtual via Windows
I have been at this simple thing and I know I am missing something. Some sort of combo of something. I have tried many things I found online and can not get this to work.

This is a virtual I am on:

[MYNAME@vd-MYNAME scripts]$ lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarchrinting-4.1-amd64rinting-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.1.1503 (Core)
Release: 7.1.1503
Codename: Core

I am trying to make this script work:

[MYNAME@vd-MYNAME scripts]$ cat ifc
#!/bin/bash

read -p "Enter first SITE number: " startSITE
read -p "Enter last SITE number: " stopSITE

#ssh -i /home/MYNAME/ssh/config

for x in `seq $startSITE $stopSITE`
do for n in 1 2
do ssh -i /home/MYNAME/ssh/id_rsa root@SITE$x-n$n ifconfig eth0; done; done

And I have these files:
/home/MYNAME/ssh/ folder is
drwxr-xr-x 2 MYNAME users 49 Aug 18 15:55 ssh

Contents are:
-rw------- 1 MYNAME users 124 Aug 18 15:55 config
-rw------- 1 MYNAME users 1675 Aug 17 22:53 id_rsa
-rw-r--r-- 1 MYNAME users 1675 Aug 17 22:55 id_rsa.ori

[MYNAME@vd-MYNAME ssh]$ cat config
Host vxms* device1* device2*
IdentityFile /home/MYNAME/ssh/id_rsa
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
User root

I should be able to log into these devices without having to add in the password each time, using the id_rsa file, but it keeps asking.

[MYNAME@vd-MYNAME scripts]$ ./ifc
Enter first SITE number: 1000
Enter last SITE number: 1000
The authenticity of host 'SITE1000-n1 (10.105.87.238)' can't be established.
RSA key fingerprint is f2:25:48:f0:97:f8:10:30:79:96:54:4f:22:cb:09:f8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'SITE1000-n1,10.106.86.226' (RSA) to the list of known hosts.
root@SITE1000-n1's password:

All logins are "root."

Can someone please assist in what I am doing wrong?

Thank you.

I reply as fast as I can, but it could be hours or months.


See More: Using RSA Key to SSH

Reply ↓  Report •

✔ Best Answer
August 22, 2017 at 06:43:04
It was an issue with the id_rsa file for me. I used one from 2016 and it worked. I pointed my script to that file.
I did not need a .ssh folder or anything extra.
My script is simply this with the new file location of an old file I had early 2016.
=============================
#!/bin/bash

read -p "Enter first site number: " startsite
read -p "Enter last site number: " stopsite

for x in `seq $startsite $stopsite`
do for n in 1 2
do ssh -i /home/name/work/keys/site_id_rsa root@site$x-n$n "ifconfig eth0"; done; done
=============================
And it works... for the moment.

I reply as fast as I can, but it could be hours or months.



#1
August 21, 2017 at 06:24:58
Have you added the public key of the client to the .ssh/authorized_keys files on the devices that you are accessing?

Reply ↓  Report •

#2
August 21, 2017 at 06:44:41
No, that is not a directory I have on this virtual.
As for the id_rsa file, I was given that to just copy over. So I amde a folder called "ssh" under my folder and copied the file.

I reply as fast as I can, but it could be hours or months.

message edited by CPU13


Reply ↓  Report •

#3
August 21, 2017 at 06:47:30
Have a look at this article: http://www.linuxproblem.org/art_9.html

That file (it may be stored in different directories on different OSs) is the one that authorizes access without password (once the password has been initially used for access). I should have added that it is in the home directory of the user accessing the machine. What OS is running on the machines you are trying to access?


Reply ↓  Report •

Related Solutions

#4
August 21, 2017 at 06:57:43
I have hundreds of devices running CentOS 6 and 7, and Fedora. A total of six different passwords could be used on any of these devices.
I tried the steps above but that would still require me to access every device with their own passwords.
The id_rsa file I was given was supposed to handle that, but the way i wrote the script just keeps asking for for passwords.

I reply as fast as I can, but it could be hours or months.


Reply ↓  Report •

#5
August 21, 2017 at 07:43:21
No, the id_rsa file is just the private key. You need the authorized_keys file on the target machine for password please logon. So, yes, you have to access each target once to create the file and put the appropriate keys in it.

Reply ↓  Report •

#6
August 21, 2017 at 09:10:13
That would take ages to do for them. Hundreds of systems each with different passwords, but yet one guy can do it and I did what he told me. I just can not keep asking him questions (he busy).
I will have to find another way.

I reply as fast as I can, but it could be hours or months.


Reply ↓  Report •

#7
August 21, 2017 at 09:20:40
When you find the answer it would be very helpful if you post it here. Others might have the same problem.

Reply ↓  Report •

#8
August 22, 2017 at 06:43:04
✔ Best Answer
It was an issue with the id_rsa file for me. I used one from 2016 and it worked. I pointed my script to that file.
I did not need a .ssh folder or anything extra.
My script is simply this with the new file location of an old file I had early 2016.
=============================
#!/bin/bash

read -p "Enter first site number: " startsite
read -p "Enter last site number: " stopsite

for x in `seq $startsite $stopsite`
do for n in 1 2
do ssh -i /home/name/work/keys/site_id_rsa root@site$x-n$n "ifconfig eth0"; done; done
=============================
And it works... for the moment.

I reply as fast as I can, but it could be hours or months.


Reply ↓  Report •

Ask Question