Run a script at remote server without ssh password


 
Thread Tools Search this Thread
Operating Systems Linux Ubuntu Run a script at remote server without ssh password
# 1  
Old 05-13-2015
Run a script at remote server without ssh password

Hello,
What I want to do is to run a file on remote server by running a script at localhost but script should not ask ssh password of my remote server when script is executed.

Scenario1:
To copy files from server2 to data server:
Code:
$ scp -r root@server2_ip:/var/www/html/*.* /var/

When I enter above code, it asks for my server2 ssh password

Scenario2:
I want to run a script existing in server1 and it will be run at server2
Code:
$ ssh ./ex.bash server2_ip "bash -s -- '<--time bye>' '<end>'"

When I enter above code in terminal, it asks for my servers ssh password.

I want to run ssh or scp commands from a script via crontab, but don't know how the script will remember remote server's ssh password.

I tried different variations but no result.
Code:
root:sshpass@server2_ip:/path
root@sshpass:server2_ip:/path

How may I do this?

Thanks in advance
Boris

Last edited by rbatte1; 10-27-2015 at 05:37 AM.. Reason: Added CODE tags and spelling
# 2  
Old 05-13-2015
You just need to set up public/private keys.

ssh-keygen Tutorial – Generating RSA and DSA keys | Guy Rutenberg
# 3  
Old 05-13-2015
Hello Gandolf989,
Thanks for your recommendation but it seems a bit intricate..
Btw, password is not localhost ssh password. It's remote server's ssh password
# 4  
Old 05-13-2015
There is really only a couple of steps:

on the local server do the following:
  1. mkdir ~.ssh
  2. chmod 750 ~
  3. chmod 700 ~/.ssh
  4. ssh-keygen -t rsa -b 2048
  5. cat id_rsa_<server_name>.pub

On the remote server do the following:
  1. mkdir ~.ssh
  2. chmod 750 ~
  3. chmod 700 ~/.ssh
  4. touch ~/.ssh/authorized_keys
  5. chmod 600 ~/.ssh/authorized_keys
  6. edit the ~/.ssh/authorized_keys and paste in the contents of the *.pub file from the local server

Then test to see if you can ssh from the local to the remote server without a password.
This User Gave Thanks to gandolf989 For This Post:
# 5  
Old 05-14-2015
Quote:
Originally Posted by gandolf989
There is really only a couple of steps:

on the local server do the following:
  1. mkdir ~.ssh
  2. chmod 750 ~
  3. chmod 700 ~/.ssh
  4. ssh-keygen -t rsa -b 2048
  5. cat id_rsa_<server_name>.pub

On the remote server do the following:
  1. mkdir ~.ssh
  2. chmod 750 ~
  3. chmod 700 ~/.ssh
  4. touch ~/.ssh/authorized_keys
  5. chmod 600 ~/.ssh/authorized_keys
  6. edit the ~/.ssh/authorized_keys and paste in the contents of the *.pub file from the local server

Then test to see if you can ssh from the local to the remote server without a password.
Thanks Gandolf,
I will test it on Saturday and will report the result.

b.regards
Boris
# 6  
Old 10-24-2015
Quote:
Originally Posted by gandolf989
There is really only a couple of steps:

on the local server do the following:
  1. mkdir ~.ssh
  2. chmod 750 ~
  3. chmod 700 ~/.ssh
  4. ssh-keygen -t rsa -b 2048
  5. cat id_rsa_<server_name>.pub

On the remote server do the following:
  1. mkdir ~.ssh
  2. chmod 750 ~
  3. chmod 700 ~/.ssh
  4. touch ~/.ssh/authorized_keys
  5. chmod 600 ~/.ssh/authorized_keys
  6. edit the ~/.ssh/authorized_keys and paste in the contents of the *.pub file from the local server

Then test to see if you can ssh from the local to the remote server without a password.


Hello,
After I enter those codes to local and remote servers, it asks again root password to establish an ssh connection. In server permit root login is prohibit. Could it be the reason?

Thanks in advance
Boris
# 7  
Old 10-27-2015
If you are connecting as root to the remote server and the setting is PermitRootLogin=no then you will be unable to do this. If you are connecting as another user (non-zero uid) then this flag will have no effect, however you have to consider what happens with the standard profiles for that account logging in, e.g. does it assume a terminal, lock you into an application etc.


Robin
This User Gave Thanks to rbatte1 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run commands on remote server using ssh password less authentication?

Hi, I need to run a script located in a directory on remote server by using ssh authentication from my local unix server. Can anyone help me in this. I have tried the below command. It worked for echo command but when i tried to open a file using cat command it is showing "cat: cannot open... (6 Replies)
Discussion started by: ssk250
6 Replies

2. Solaris

Script to get files from remote server to local server through sftp without prompting for password

Hi, I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script. Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies

3. Shell Programming and Scripting

Script to ssh to remote server

Hi All, I need to prepare a script. Description: Currently i am in server "x(ubuntu os)", here i need to develop a script to ssh to another server "y(ubuntu os)", i have password less authentication to "y". i have done the below #!/bin/bash #ssh to the server "y" and confirming i am... (2 Replies)
Discussion started by: kumar85shiv
2 Replies

4. Shell Programming and Scripting

Copy and run that script in Remote server

Hi All, I need script to perform below task. 1. I have a script in one server and need to copy this script to remote server 2. login in to remote server 3. run the script which i copied to this server. #!/bin/bash read a scp /tmp/script.sh user@hostname:/tmp ssh user@$a ./scirpt.sh ... (2 Replies)
Discussion started by: bapu1981
2 Replies

5. UNIX for Dummies Questions & Answers

how to use ssh to run shell script on a remote machine?

how to use ssh to run shell script on a remote machine? ssh user@remote sh ./script.unx i ran the above command ./script.unx HAS NOHUP COMMAND IN ITS BODY, I AM GETTING ERROR AS NOHUP NOT FOUND... i tried to run that script from remote server, its working fine do ineed to set... (6 Replies)
Discussion started by: only4satish
6 Replies

6. Shell Programming and Scripting

Need help on how to exit a script run on a server from a remote server

hi, I am using the below line to run a script from remote server(say server A) to another server(say server B). ssh username@servername ksh script name. The issue is the script logs into server B, executes the script on server B, transfers the file to server A but does not exit from... (4 Replies)
Discussion started by: yohasini
4 Replies

7. Shell Programming and Scripting

[SSH] Need to connect to remote server as different user and without password

I have a task requiring that USER_A run a script, which connects to HOST_B as USER_B and does not ask for a password. If I am logged in on HOST_A as USER_B, I can connect to HOST_B without a password, no problem. However, if I try running ssh with the command line "ssh USER_B@HOST_B" while... (3 Replies)
Discussion started by: Totengraber
3 Replies

8. Shell Programming and Scripting

Ability to run sas prog on remote server using SSH

Hi, I am trying to run a sas prog on a remote server using ssh. I have got the command that I am using in the below paragraph. With it, I was able to run shell scripts but when I tried 'sas' it errored out. I have got my keys exchanged so when I say ssh serverA I automatically connect to my... (4 Replies)
Discussion started by: coolavi
4 Replies

9. Shell Programming and Scripting

run a application from a remote server via script?

I have a ksh script that does a bunch of things, then runs telnet server_b I then manually login, manually run one command (which launches an application with display back to my workstation), then logout at which point the main script takes back over, runs something else, then ends. Is... (4 Replies)
Discussion started by: yankee428
4 Replies

10. Shell Programming and Scripting

Issues using ssh from crontab to run remote script from

I have a solaris9 x86 server using ssh as follows: SSH Version Sun_SSH_1.0, protocol versions 1.5/2.0. The remote server solaris9 sparc has exactly the same version ssh installed. I am running a script on my server which includes the following command to run a script on the remote server:... (4 Replies)
Discussion started by: frustrated1
4 Replies
Login or Register to Ask a Question