How to pass password and prompt user for IP address while doing ssh and scp?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pass password and prompt user for IP address while doing ssh and scp?
# 1  
Old 03-06-2014
How to pass password and prompt user for IP address while doing ssh and scp?

Hi All,

I want to copy /.ssh/OM.pub file from source to destination.
Here source IP address, username and password is always fixed.
Whereas destination server IP address, password always gets changed.

From destination server :-
I am trying to write a script in which it should log in to source without asking for password (as it is fixed).
And get the file and put in destination server

Below credentials are for source server
username = root
password = shroot


Code:
#!/bin/sh

echo "%%%%%%I am at destination server%%%%%%%%"
echo "%%%%%% log in to source %%%%%%%"
ssh root@10.34.80.53 (here how to pass "shroot" automatically in script)
scp ~/.ssh/id_rsa.pub root@ASK_USER_FOR_DESTINATION_SERVER_IP:/tmp/id_rsa.pub
exit

echo "%%%%%%I am at destination server%%%%%%%%"
cat /tmp/id_rsa.pub >> ~/.ssh/authorized_keys;rm /tmp/id_rsa.pub; chmod 0600 ~/.ssh/


Regards,
Madhur
# 2  
Old 03-06-2014
If ftp is enabled on the source server, try this ftp

I am not aware of anything clean to send password via ssh other than expect.

--ahamed
# 3  
Old 03-06-2014
If you have Expect available, this will work:

Code:
#!/usr/bin/expect -f
#
# send a single file via scp
#
#

# check command-line for correct number of
# arguments
if {[llength $argv] != 3} {
    puts stderr "Usage: sendfile </path/to/file> <host> <remote directory>"
    exit 1
}

# store argument
set f [lindex $argv 0]
set h [lindex $argv 1]
set d [lindex $argv 2]

# set credentials
set u "root"
set p "shroot"

# send the file to the given host
spawn scp $f $u@$h:$d

# handle the password prompt
expect "?assword:*"
send -- "$p\r"
send -- "\r"

# done
expect eof

c536622c3315ac7f830107200232a62f
# 4  
Old 03-06-2014
FYI... a .netrc file is the traditional means to automate login into ftp servers. Ftp as well as the use of .netrc files are not recommended.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Sudo Password Prompt over SSH

I am not sure what I am missing here. I have the following identical entry in /etc/sudoers on multiple Red Hat 6.4 servers. icinga ALL=NOPASSWD:/usr/bin/yum --security --exclude\="kernel*" check-update On one server when I enter the command over SSH as follows it works fine. ssh -t -q... (1 Reply)
Discussion started by: scotbuff
1 Replies

2. SuSE

SLES 11.2 slow SSH password prompt

We are having an issue with slow password prompts via SSH login on all of our SLES 11.2 boxes. The output from a ssh -v login attempt shows a delay here: debug1: SSH2_MSG_SERVICE_ACCEPT receivedThis issue only happens on the first logon of the day; subsequent logons are normal. Adding the client's... (8 Replies)
Discussion started by: j_aix
8 Replies

3. Shell Programming and Scripting

unable to pass value to user prompt from calling shell script

This is my script structure main script calls configure script which needs to be run as a different user and the configure script calls my application installation script. the application instruction script prompts the user for a directory which I need to pass from my main or configure script. ... (4 Replies)
Discussion started by: cmastays
4 Replies

4. Programming

Test SSH but do not return password prompt

Hello forum, I want to have a function to test for passwordless SSH setup. Pretty simple. However, what I'm finding difficult is to NOT return a password prompt to screen IF it's not in place. Here's the function: check_passwordless_ssh_working() #check passed parameter, assuming it is... (4 Replies)
Discussion started by: doonan_79
4 Replies

5. Shell Programming and Scripting

How to pass the password as input parameter to scp

Dear all Does anybody know how to pass the password as input parameter to scp or rsync in unix scripts? I have tried echo <password> | scp filename username@<ip address>:/filepath/ . But it does not work. BTW, I dont want to setup ssh trust between servers in this adhoc task. Regards,... (2 Replies)
Discussion started by: eldonlck
2 Replies

6. Solaris

expired password prompt at ssh login

Hi, I am using DSEE 6.3 to authenticate and authorize my Solaris 9 and 10 users. Everything works fine except password expiration. I use built-in global password policy for all users. The policy works well. However I could not find the right pam configuration in order to prompt users at ssh... (2 Replies)
Discussion started by: niyazi
2 Replies

7. UNIX for Dummies Questions & Answers

SSH version of rlogin (ie without password prompt)

I have 3 Solaris 10 UNIX servers, the shadow and passwd file are all identical and are automatically sync every 5 minutes. A majority of the users do not have CLI access but rather use a menu. I currently have menu options that allows them to rlogin to another server and I need to have the... (1 Reply)
Discussion started by: creedonjm
1 Replies

8. Linux

SSH user equivalency still prompt for password

Hi All, I've followed the exact same steps of how to setup and enable SSH user equivalent including the right permission, but when I "ssh" it still prompts for password. Could you help to see what I did wrong? I appreciate any helps. :confused: server1.com:/u01/oracle RAC1 > mkdir... (2 Replies)
Discussion started by: Beginer0705
2 Replies

9. OS X (Apple)

No command prompt after SSH/SCP

Recently whenever I log out of an SSH session, or copy something using SCP, I get no response from my shell. Running with ssh -v showed no errors when exiting. Normally I could deal with this, but I believe it's causing errors elsewhere when scripts try to download things from external... (0 Replies)
Discussion started by: keymakerOvvvv
0 Replies

10. HP-UX

sftp/scp/ssh script with password as authentication

Hello, Do you guys know set of commands that can incorporate to sftp/scp/ssh to add password in a script to automate file transfer. Our client is not using ssh keys authentication so we are force to create a script to pass the password into the script to transfer files via sftp/scp/ssh. We... (4 Replies)
Discussion started by: james_falco
4 Replies
Login or Register to Ask a Question