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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to run commands on remote server using ssh password less authentication?
# 1  
Old 01-29-2015
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 the <filename>". I have given the required permissions as well.

Code:
ssh <username>@<ipaddress> cd <path>;cat <filename>

thanks in advance.
# 2  
Old 01-29-2015
Quote:
Originally Posted by ssk250
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 the <filename>". I have given the required permissions as well.

Code:
ssh <username>@<ipaddress> cd <path>;cat <filename>

thanks in advance.
Have you tried putting those commands into a script?

ie:

Code:
echo "cd <path>" >file1.ksh
echo "cat <filename>" >> file1.ksh
chmod +x file1.ksh

make sure it's owned by <username>

then try again:

Code:
ssh <username>@<ipaddress> <path_to_file1.ksh>/file1.ksh

??
This User Gave Thanks to Ditto For This Post:
# 3  
Old 01-29-2015
Did the cd <path> succeed, and does <filename> exist in that path?
# 4  
Old 01-29-2015
The problem here is that the cat is running locally. Your local shell is seeing the semicolon as a command separator between the ssh command and the cat command. Try quoting the command string to send it to the remote side eg:

Code:
ssh <username>@<ipaddress> "cd <path>;cat <filename>"

or

Code:
ssh <username>@<ipaddress> cd <path>\;cat <filename>

If you have a more complex command e.g. involving awk I'd suggest a here-doc:

Code:
ssh <username>@<ipaddress> <<"EOF"
    cd /var/log/httpd
    awk '/Invalid method/ { print $5} ' error_log
EOF

This User Gave Thanks to Chubler_XL For This Post:
# 5  
Old 01-29-2015
Have you tried
ssh user@host cat /path-to-file/file ?
This User Gave Thanks to JustaDude For This Post:
# 6  
Old 02-01-2015
When i tried the commands above I am getting the below error

"cannot open <filename>"

Is it that there will be no permission to execute/open files using commands on remote server?
# 7  
Old 02-01-2015
Remote server will have same permissions to the filesystem that the "username" user has.

Why not try running the command from an interactive shell you can then debug/sort out required permissions:

Code:
$ ssh username@ipaddress
Last login: Fri Jan 30 16:19:27 2015 from your-pc.your.domain

ipaddress $ cat /path-to-file/file
This is the file contents

ipaddress $ exit
Connection to ipaddress closed.

$

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

Ssh - running commands on remote server

Hi, I am trying to run commands on a list of servers that I can ssh to and just want to know if there is a 'cleaner' way of doing this. At the moment, I am doing as below. Is there a way that I can escape the double quote differently? If a use a single quote to enclose the commands that I... (1 Reply)
Discussion started by: newbie_01
1 Replies

3. Shell Programming and Scripting

Running Commands on a Remote Linux Server over SSH

Hello, I'm trying to create a ksh script to ssh to a remote server, enter the password and a couple commands. For security reasons I have changed the login, password and ip in my example. #!/bin/ksh ssh -t -t username@12.5.5.3 << EOF password cd bin pwd EOF When I run it. It... (5 Replies)
Discussion started by: seekryts15
5 Replies

4. IP Networking

Cygwin remote ssh with key authentication method

Hi experts, I am not sure in which forum to submit this question. If this is not the correct place then please let me know where to submit this thread. My requirement is to invoke windows batch scripts from linux shell script. Hence, I have installed openssh in Cygwin on the windows machine.... (2 Replies)
Discussion started by: ahmedwaseem2000
2 Replies

5. Red Hat

prompting for passwords even i configured ssh password less authentication

There are two servers : 1. Site 2. Testing from site server i want to connect testing server with ssh password less authentication. i generated public and private keys with ssh-keygen -t rsa on site server. cat id_rsa >> authorized_keys cat id_rsa.pub >> authorized_keys i... (15 Replies)
Discussion started by: rehantayyab82
15 Replies

6. UNIX for Dummies Questions & Answers

SSH Keys Authentication keeps asking for password

Hi! Im trying to set access from ServerA(SunOS) to ServerB(Some custom Linux with Keyboard Interactive login) with SSH Keys. As a proof of concept I was able to do it between 2 virtual machines. Now in my real life scenario it isnt working. I created the keys in ServerA, copied them to... (7 Replies)
Discussion started by: RedSpyder
7 Replies

7. Shell Programming and Scripting

executing commands in remote server using ssh

I have some commands which need to be executed in remote machine. I have Linux Server from where I need to connect to Solaris server using ssh and then declare some variable over there and run some commands. I don't want to call a script which is present in Solaris server from Linux server... (7 Replies)
Discussion started by: maitree
7 Replies

8. Solaris

how to login with ssh to remote system with out applying the remote root/usr password

how to login with ssh to remote system with out applying the remote root/user password with rlogin we can ujse .rhosts file but with ssh howits possible plz guide (2 Replies)
Discussion started by: tv.praveenkumar
2 Replies

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

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