Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 1 character in body
Source Link
fuser
  • 727
  • 3
  • 18
  • 30

Here is my problem: I would like to perform scp command after ssh to remote server without typing any passwords. I describe my steps. My first steps were:

ssh-keygen -t rsa and

local@host$ ssh-copy-id -i /root/.ssh/id_rsa.pub remote@host on local machine

Then I did the same on remote machine:

ssh-keygen -t rsa and

remote@host$ ssh-copy-id -i /root/.ssh/id_rsa.pub local@host

After all described above I could do ssh on both machines without typing any password. I could perform scp command on remote machine like scp /home/remote/info.txt.gz local@host:/root/ and everything worked perfectly.

Then I tried to make a script with some actions described below and the last step in my script was scp command that did not work as I expected.

#!/bin/bash remote_user=$1 remote_host=$2 local_user=$3 local_host=$4 echo "Testing connection to ${host}..." ssh -n -o NumberOfPasswordPrompts=0 ${remote_user}@${remote_host} if [ $? -ne 0 ]; then echo "FATAL: You don't have passwordless ssh working." echo "Try running ssh-keygen" exit 1 fi echo "Okey. Starting the process." ssh ${remote_user}@${remote_host} netstat -tulpn > /home/${remote_user}/info.txt;uptime |awk '{ print $3 }' >> /home/${remote_user}/info.txt; if [ $? -ne 0 ]; then echo "An error occurred." else echo "File is ready for gzipping!" fi gzip /home/${remote_user}/info.txt if [ $? -ne 0 ]; then echo "file was not archived" else echo "Archive is ready!" fi echo "Starting copy archive from ${remote_host} to ${local_host}" scp /home/${remote_user}/info.txt.gz ${local_user}@${local_host}:/root/ if [ $? -ne 0 ]; then echo "Error while transferring!" else echo "Copy has been transferred successfully!" fi 

Scp command asked me for password o_O.

When I did all steps in script manually everything worked perfectly but in script scp demanded password. I read a lot through stackexchange and found this answer Using an already established SSH channel. This answer requires Open SSH but my problem can be resolved manually via SSH as I said but in script it did not work. What am I going to do to make scp works without password?

Here is my problem: I would like to perform scp command after ssh to remote server without typing any passwords. I describe my steps. My first steps were:

ssh-keygen -t rsa and

local@host$ ssh-copy-id -i /root/.ssh/id_rsa.pub remote@host on local machine

Then I did the same on remote machine:

ssh-keygen -t rsa and

remote@host$ ssh-copy-id -i /root/.ssh/id_rsa.pub local@host

After all described above I could do ssh on both machines without typing any password. I could perform scp command on remote machine like scp /home/remote/info.txt.gz local@host:/root/ and everything worked perfectly.

Then I tried to make a script with some actions described below and the last step in my script was scp command that did not work as I expected.

#!bin/bash remote_user=$1 remote_host=$2 local_user=$3 local_host=$4 echo "Testing connection to ${host}..." ssh -n -o NumberOfPasswordPrompts=0 ${remote_user}@${remote_host} if [ $? -ne 0 ]; then echo "FATAL: You don't have passwordless ssh working." echo "Try running ssh-keygen" exit 1 fi echo "Okey. Starting the process." ssh ${remote_user}@${remote_host} netstat -tulpn > /home/${remote_user}/info.txt;uptime |awk '{ print $3 }' >> /home/${remote_user}/info.txt; if [ $? -ne 0 ]; then echo "An error occurred." else echo "File is ready for gzipping!" fi gzip /home/${remote_user}/info.txt if [ $? -ne 0 ]; then echo "file was not archived" else echo "Archive is ready!" fi echo "Starting copy archive from ${remote_host} to ${local_host}" scp /home/${remote_user}/info.txt.gz ${local_user}@${local_host}:/root/ if [ $? -ne 0 ]; then echo "Error while transferring!" else echo "Copy has been transferred successfully!" fi 

Scp command asked me for password o_O.

When I did all steps in script manually everything worked perfectly but in script scp demanded password. I read a lot through stackexchange and found this answer Using an already established SSH channel. This answer requires Open SSH but my problem can be resolved manually via SSH as I said but in script it did not work. What am I going to do to make scp works without password?

Here is my problem: I would like to perform scp command after ssh to remote server without typing any passwords. I describe my steps. My first steps were:

ssh-keygen -t rsa and

local@host$ ssh-copy-id -i /root/.ssh/id_rsa.pub remote@host on local machine

Then I did the same on remote machine:

ssh-keygen -t rsa and

remote@host$ ssh-copy-id -i /root/.ssh/id_rsa.pub local@host

After all described above I could do ssh on both machines without typing any password. I could perform scp command on remote machine like scp /home/remote/info.txt.gz local@host:/root/ and everything worked perfectly.

Then I tried to make a script with some actions described below and the last step in my script was scp command that did not work as I expected.

#!/bin/bash remote_user=$1 remote_host=$2 local_user=$3 local_host=$4 echo "Testing connection to ${host}..." ssh -n -o NumberOfPasswordPrompts=0 ${remote_user}@${remote_host} if [ $? -ne 0 ]; then echo "FATAL: You don't have passwordless ssh working." echo "Try running ssh-keygen" exit 1 fi echo "Okey. Starting the process." ssh ${remote_user}@${remote_host} netstat -tulpn > /home/${remote_user}/info.txt;uptime |awk '{ print $3 }' >> /home/${remote_user}/info.txt; if [ $? -ne 0 ]; then echo "An error occurred." else echo "File is ready for gzipping!" fi gzip /home/${remote_user}/info.txt if [ $? -ne 0 ]; then echo "file was not archived" else echo "Archive is ready!" fi echo "Starting copy archive from ${remote_host} to ${local_host}" scp /home/${remote_user}/info.txt.gz ${local_user}@${local_host}:/root/ if [ $? -ne 0 ]; then echo "Error while transferring!" else echo "Copy has been transferred successfully!" fi 

Scp command asked me for password o_O.

When I did all steps in script manually everything worked perfectly but in script scp demanded password. I read a lot through stackexchange and found this answer Using an already established SSH channel. This answer requires Open SSH but my problem can be resolved manually via SSH as I said but in script it did not work. What am I going to do to make scp works without password?

Here is my problem: I would like to perform scp command after ssh to remote server without typing any passwords. I describe my steps. My first steps were:

ssh-keygen -t rsa and

local@host$ ssh-copy-id -i /root/.ssh/id_rsa.pub remote@host on local machine

Then I did the same on remote machine:

ssh-keygen -t rsa and

remote@host$ ssh-copy-id -i /root/.ssh/id_rsa.pub local@host

After all described above I could do ssh on both machines without typing any password. I could perform scp command on remote machine like scp /home/remote/info.txt.gz local@host:/root/ and everything worked perfectly.

Then I tried to make a script with some actions described below and the last step in my script was scp command that did not work as I expected.

#!bin/bash remote_user=$1 remote_host=$2 local_user=$3 local_host=$4 echo "Testing connection to ${host}..." ssh -n -o NumberOfPasswordPrompts=0 ${remote_user}@${remote_host} if [ $? -ne 0 ]; then  echo "FATAL: You don't have passwordless ssh working."  echo "Try running ssh-keygen"  exit 1 fi echo "Okey. Starting the process." ssh ${remote_user}@${remote_host} netstat -tulpn > /home/${remote_user}/info.txt;uptime |awk '{ print $3 }' >> /home/${remote_user}/info.txt; if [ $? -ne 0 ]; then  echo "An error occurred." else  echo "File is ready for gzipping!" fi gzip /home/${remote_user}/info.txt if [ $? -ne 0 ]; then  echo "file was not archived" else  echo "Archive is ready!" fi echo "Starting copy archive from ${remote_host} to ${local_host}" scp /home/${remote_user}/info.txt.gz ${local_user}@${local_host}:/root/ if [ $? -ne 0 ]; then  echo "Error while transferring!" else  echo "Copy has been transferred successfully!" fi 

Scp command asked me for password o_O.

When I did all steps in script manually everything worked perfectly but in script scp demanded password. I read a lot through stackexchange and found this answer Using an already established SSH channel. This answer requires Open SSH but my problem can be resolved manually via SSH as I said but in script it did not work. What am I going to do to make scp works without password?

Here is my problem: I would like to perform scp command after ssh to remote server without typing any passwords. I describe my steps. My first steps were:

ssh-keygen -t rsa and

local@host$ ssh-copy-id -i /root/.ssh/id_rsa.pub remote@host on local machine

Then I did the same on remote machine:

ssh-keygen -t rsa and

remote@host$ ssh-copy-id -i /root/.ssh/id_rsa.pub local@host

After all described above I could do ssh on both machines without typing any password. I could perform scp command on remote machine like scp /home/remote/info.txt.gz local@host:/root/ and everything worked perfectly.

Then I tried to make a script with some actions described below and the last step in my script was scp command that did not work as I expected.

#!bin/bash remote_user=$1 remote_host=$2 local_user=$3 local_host=$4 echo "Testing connection to ${host}..." ssh -n -o NumberOfPasswordPrompts=0 ${remote_user}@${remote_host} if [ $? -ne 0 ]; then echo "FATAL: You don't have passwordless ssh working." echo "Try running ssh-keygen" exit 1 fi echo "Okey. Starting the process." ssh ${remote_user}@${remote_host} netstat -tulpn > /home/${remote_user}/info.txt;uptime |awk '{ print $3 }' >> /home/${remote_user}/info.txt; if [ $? -ne 0 ]; then echo "An error occurred." else echo "File is ready for gzipping!" fi gzip /home/${remote_user}/info.txt if [ $? -ne 0 ]; then echo "file was not archived" else echo "Archive is ready!" fi echo "Starting copy archive from ${remote_host} to ${local_host}" scp /home/${remote_user}/info.txt.gz ${local_user}@${local_host}:/root/ if [ $? -ne 0 ]; then echo "Error while transferring!" else echo "Copy has been transferred successfully!" fi 

Scp command asked me for password o_O.

When I did all steps in script manually everything worked perfectly but in script scp demanded password. I read a lot through stackexchange and found this answer Using an already established SSH channel. This answer requires Open SSH but my problem can be resolved manually via SSH as I said but in script it did not work. What am I going to do to make scp works without password?

Here is my problem: I would like to perform scp command after ssh to remote server without typing any passwords. I describe my steps. My first steps were:

ssh-keygen -t rsa and

local@host$ ssh-copy-id -i /root/.ssh/id_rsa.pub remote@host on local machine

Then I did the same on remote machine:

ssh-keygen -t rsa and

remote@host$ ssh-copy-id -i /root/.ssh/id_rsa.pub local@host

After all described above I could do ssh on both machines without typing any password. I could perform scp command on remote machine like scp /home/remote/info.txt.gz local@host:/root/ and everything worked perfectly.

Then I tried to make a script with some actions described below and the last step in my script was scp command that did not work as I expected.

#!bin/bash remote_user=$1 remote_host=$2 local_user=$3 local_host=$4 echo "Testing connection to ${host}..." ssh -n -o NumberOfPasswordPrompts=0 ${remote_user}@${remote_host} if [ $? -ne 0 ]; then  echo "FATAL: You don't have passwordless ssh working."  echo "Try running ssh-keygen"  exit 1 fi echo "Okey. Starting the process." ssh ${remote_user}@${remote_host} netstat -tulpn > /home/${remote_user}/info.txt;uptime |awk '{ print $3 }' >> /home/${remote_user}/info.txt; if [ $? -ne 0 ]; then  echo "An error occurred." else  echo "File is ready for gzipping!" fi gzip /home/${remote_user}/info.txt if [ $? -ne 0 ]; then  echo "file was not archived" else  echo "Archive is ready!" fi echo "Starting copy archive from ${remote_host} to ${local_host}" scp /home/${remote_user}/info.txt.gz ${local_user}@${local_host}:/root/ if [ $? -ne 0 ]; then  echo "Error while transferring!" else  echo "Copy has been transferred successfully!" fi 

Scp command asked me for password o_O.

When I did all steps in script manually everything worked perfectly but in script scp demanded password. I read a lot through stackexchange and found this answer Using an already established SSH channel. This answer requires Open SSH but my problem can be resolved manually via SSH as I said but in script it did not work. What am I going to do to make scp works without password?

Source Link
fuser
  • 727
  • 3
  • 18
  • 30

Scp command over ssh without password in script

Here is my problem: I would like to perform scp command after ssh to remote server without typing any passwords. I describe my steps. My first steps were:

ssh-keygen -t rsa and

local@host$ ssh-copy-id -i /root/.ssh/id_rsa.pub remote@host on local machine

Then I did the same on remote machine:

ssh-keygen -t rsa and

remote@host$ ssh-copy-id -i /root/.ssh/id_rsa.pub local@host

After all described above I could do ssh on both machines without typing any password. I could perform scp command on remote machine like scp /home/remote/info.txt.gz local@host:/root/ and everything worked perfectly.

Then I tried to make a script with some actions described below and the last step in my script was scp command that did not work as I expected.

#!bin/bash remote_user=$1 remote_host=$2 local_user=$3 local_host=$4 echo "Testing connection to ${host}..." ssh -n -o NumberOfPasswordPrompts=0 ${remote_user}@${remote_host} if [ $? -ne 0 ]; then echo "FATAL: You don't have passwordless ssh working." echo "Try running ssh-keygen" exit 1 fi echo "Okey. Starting the process." ssh ${remote_user}@${remote_host} netstat -tulpn > /home/${remote_user}/info.txt;uptime |awk '{ print $3 }' >> /home/${remote_user}/info.txt; if [ $? -ne 0 ]; then echo "An error occurred." else echo "File is ready for gzipping!" fi gzip /home/${remote_user}/info.txt if [ $? -ne 0 ]; then echo "file was not archived" else echo "Archive is ready!" fi echo "Starting copy archive from ${remote_host} to ${local_host}" scp /home/${remote_user}/info.txt.gz ${local_user}@${local_host}:/root/ if [ $? -ne 0 ]; then echo "Error while transferring!" else echo "Copy has been transferred successfully!" fi 

Scp command asked me for password o_O.

When I did all steps in script manually everything worked perfectly but in script scp demanded password. I read a lot through stackexchange and found this answer Using an already established SSH channel. This answer requires Open SSH but my problem can be resolved manually via SSH as I said but in script it did not work. What am I going to do to make scp works without password?