How to run command on remote server?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to run command on remote server?
# 8  
Old 11-16-2016
The SSH protocol tools are designed not to accept plaintext passwords because of the insecurity of storing a short plaintext password (in a script or reference file etc.)

To automate the procedure, you should generate SSH keys. This will give you a secure connection which you can automate far easier than trying to force in credentials, similar to the 4-line loop shown above.

How far do you get with the ssh-keygen command and sharing the public key?




Robin
# 9  
Old 11-16-2016
hi rbatte1

I have done ssh key gen.
but still it is not allowing me to do it.

below is the command which I am giving

Code:
cat id_rsa.pub | ssh root@10.192.85.95 'cat >> .ssh/authorized_keys;exit;'

it ask for the password but when I give it is not accepting.
# 10  
Old 11-16-2016
Does it accept the password when logging in interactively?
# 11  
Old 11-16-2016
yes it accept intractively

my restrictions is
i can not use sshpass or expect or keygen

is there any alternative to login with root user
even i don't mind giving password in script.

scriptor

Last edited by scriptor; 11-16-2016 at 07:49 AM.. Reason: typo error
# 12  
Old 11-16-2016
Connect with sftp and then put the file instead:-
Code:
$ cd ~/.ssh

$ sftp root@ip.add.re.ss
root@10.4.202.99's password: 
sftp> mkdir .ssh
sftp> cd .ssh
sftp> put id_rsa.pub scriptor.pub
sftp> quit

$ ssh root@ip.add.re.ss
root@ip.add.re.ss's password: 
# cd .ssh
# cat scriptor.pub >> authorized_keys
# chmod 600 authorized_keys
# chmod 700 .
# exit

$ ssh root@ip.add.re.ss  "date ; hostname ; uname -a ; echo 'Hello scriptor' "

If the directory creation fails, that's okay if it has already have been created. The appending of your public key to the authorized_keys file makes sure you do not destroy any existing keys in place.

The permissions settings need to be tight or ssh will refuse to use them.



I hope that this helps,
Robin
# 13  
Old 11-16-2016
hi

I have already done it but not working. although the same procedure is working for other node.


I am ok in writing the password in the script.

is there any way through which I can write a script ?
# 14  
Old 11-16-2016
By design, ssh is written to prevent forcing in the password from a script. What messages do you get to screen or to the system logs on the target server? You might need to look in /etc/syslog.conf or /etc/rsyslog.conf to see where the logs are written.

If we can work out where it is failing, we should be able to get it fixed in the correct way rather than a brute-force way in a script.



Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

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:$ scp -r root@server2_ip:/var/www/html/*.* /var/ When I enter... (6 Replies)
Discussion started by: baris35
6 Replies

2. 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

3. Shell Programming and Scripting

Run scripts on remote server

I have a sql script in my parent server - host1 i can do a passwordless ssh to remote server - host1a and host1b Can i run the sql script which is present in host1 by connecting to host1a and host1b. Should i place the sql script in host1a and host1b ? Is there a way i can run without placing... (2 Replies)
Discussion started by: Nagesh_1985
2 Replies

4. Shell Programming and Scripting

To run a shell script in remote server from windows batch file

Hi all, i need to run a shell script on remote server. I have created file .bat file in windows server with following code, c:\Users\Desktop\putty.exe -ssh -pw password user@server ./script.sh i need to run the script.sh in my remote server Above command is not working, any... (4 Replies)
Discussion started by: rammm
4 Replies

5. Shell Programming and Scripting

Until string from remote command equals value run remote command

I solved my issue by using the following code #!/bin/bash function GET_STATUS { #values Active Passive Failed ssh -a localhost '/home/user/fakecommand.sh' } STATE="unknown" until ] do echo $STATE sleep 5 STATUS=`GET_STATUS` echo $STATUS | grep Active &&... (1 Reply)
Discussion started by: $scipt_Kid
1 Replies

6. Shell Programming and Scripting

Need script to run the command in remote server

hi, I need script to perform below task. 1. Read the IP address 2. copy the script from origin server to destination. 3. get root access on destination server 4. run the script on destination server 5. return to the origin server Code: #!/bin/bash echo "Enter Server IP... (5 Replies)
Discussion started by: bapu1981
5 Replies

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question