Ssh passwd less, shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ssh passwd less, shell script
# 1  
Old 11-21-2016
RedHat Ssh passwd less, shell script

Hi All, Wishes!!
I need some help to prepare a script to copy the public key from admin host to multiple client hosts to make them login without password.

Detailed :
I have an admin host "admin1" and i generated sshkeygen, now i have id_rsa.pub and i have around 50 client hosts. i want to copy the admin1 public key to all clients.

from admin1, i wrote the small while loop,

Code:
while read line
do
    ssh-copy-id -i ~/.ssh/id_rsa.pub $line
done < clients.txt

Moderator's Comments:
Mod Comment Code tags added

but, here if i run the script, for every client i need to enter "yes" and then "password" for each client.

please suggest me to automate the same without entering "yes" and then "password" for each host.

Thanks
kumar
# 2  
Old 11-22-2016
Hi, maybe, you can use sshpass:
Example with uniq password:
Code:
SSHPASS=your_password
while read line
do
  sshpass -e ssh-copy-id -i ~/.ssh/id_rsa.pub $line
done < clients.txt

See manpage for other options.

Regards.
# 3  
Old 11-22-2016
So what you want to do is to put a public key into place without authenticating. Would you be happy if your uses did this and could overwrite the authorised public key too?

If there is a plain FTP server on each box you want to connect to and you have credentials that will let you FTP to each of them, then you can certainly script that to put the public key in the correct location.

Smilie Make sure that your don't overwrite the existing authorized_keys file in case it's already in sue for something else. Smilie

Smilie Make sure that you get the permissions correct: mode 700 for ~/.ssh and mode 600 for files under ~/.ssh Smilie

Another way you might achieve this could be if you have a backup/restore agent on each, get the software to 'restore' your file to each in turn, but that might be more cumbersome that putting in your credentials in the first place and runs the risk of overwriting just the same.


I hope that this helps,
Robin
# 4  
Old 11-22-2016
Hi rbatte1,
ssh-copy-id changes the permissions of the remote user's home, ~/.ssh, and ~/.ssh/authorized_keys to remove group writability (which would otherwise prevent you from logging in, if the remote sshd has StrictModes set in its configuration). And append key to ~/.ssh/authorized_keys on the remote machine (creating the file, and directory, if necessary).
Regards.
# 5  
Old 11-23-2016
We still have to get an authenticated connection open in some way. I've not used ssh-copy-id but I assume it prompts for password in a similar way to ssh in that it is secure and you cannot just pipe input to it. I don't have a test server to try it out on though.


Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Cybersecurity

Ssh acces without passwd from unique machine to all servers

hello i want to acces to many machines over LAN network from a unique machine , that allow me to use a SSH directly without password. i ama using redhat enterprise version . i didnt find the right way to realise that. what should i do at first ? (1 Reply)
Discussion started by: wassimpb
1 Replies

2. Shell Programming and Scripting

Dont want to mention user id passwd in shell script

Hi, i have one shell script which transfers files from one server to other server through FTP, but i can see login id and password is not mentioned. kindly help to understand the script.then how below script is working if login and password is not mentioned in script #!/bin/sh... (1 Reply)
Discussion started by: ni3b007
1 Replies

3. Linux

ssh and passwd scripting execution problems on linux

I'm having a problem here and I was wondering if anyone could help me? I'm putting together a password script. First off, I don't have root access. I have sudo access. Lets say the User ID is Trevor1, the password is H!rry23! and the server name is Linux1234 This is how the script begins ... (5 Replies)
Discussion started by: wdog17
5 Replies

4. UNIX for Advanced & Expert Users

SSH using shell script terminates the script execution

Hello, I am writing a shell script in which i do ssh to remote server and count the number of files there and then exit. After the exit the shell script terminates which i believe is expected behavior. Can some one suggest me a way where even after the exit the script execution resumes. ... (2 Replies)
Discussion started by: manaankit
2 Replies

5. Shell Programming and Scripting

Help required to write shell script to change passwd

Hi All, I wanted to write a shell script which will change the expired passwd in oracle. Here is below what I am trying, #!/bin/sh set -x ORACLE_HOME="/optware/oracle/9.2.0.2_64" SQLPLUS="${ORACLE_HOME}/bin/sqlplus" PASS="xyz" PATH=$ORACLE_HOME/bin:$PATH... (0 Replies)
Discussion started by: gr8_usk
0 Replies

6. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

7. Solaris

Change passwd for bulk servers using SSH script

Hi, I need to Change passwd for bulk servers using SSH script. I have one server, from which i can reach all the servers without password via SSH. There is some expect script, from which i can achieve it. Can any one help me out here. Thanks in advance. Vicky (1 Reply)
Discussion started by: vickyingle5
1 Replies

8. Solaris

Solaris 10 allow ssh login with empty passwd

I have turned off PermitEmptyPasswords in sshd_config, but a user with empty passwd (deleted by passwd -d user) can still login without password, why? it is big security concern, linux doesn't have the issue. $ uname -a SunOS 5.10 Generic_118855-14 i86pc i386 i86pc ... (8 Replies)
Discussion started by: honglus
8 Replies

9. UNIX for Advanced & Expert Users

possible to lock accounts (passwd -l) and still allow acct to ssh to other server?

My scenario is as follows: We have a handful of batch accounts that run our production jobs. Our users are able to use sudo to become that account. Also, because of other reasons, the passwords are also listed in an encrypted file that each team can see their batch ID. So, I have some users... (5 Replies)
Discussion started by: cpolikowsky
5 Replies

10. Shell Programming and Scripting

passwd in shell script

Is there a way to change user password using passwd command in shell script? I don't want to use expect. Please help (8 Replies)
Discussion started by: corny
8 Replies
Login or Register to Ask a Question