LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-27-2009, 08:07 PM   #1
abefroman
Senior Member
 
Registered: Feb 2004
Location: Chicago
Distribution: CentOS w/Cpanel
Posts: 1,134

Rep: Reputation: 51
How can I append to a file remotely using a linux command (via ssh keys)


How can I append to a file remotely using a linux command (via ssh keys)

This is what I have so far:
Code:
ssh root@server1 "echo '55.55.55.55 ssh-rsa AAAABasdfaser45234234asdfasdfR0PxE' >>/root/.ssh/known_hosts"
I also tried:
Code:
ssh root@server1 `echo "55.55.55.55 ssh-rsa AAAABasdfaser45234234asdfasdfR0PxE" >>/root/.ssh/known_hosts`
and both are giving the error:
Code:
sh: /root/.ssh/known_hosts: Permission denied
And also I tried:
Code:
ssh root@server1 `echo 55.55.55.55 ssh-rsa AAAABasdfaser45234234asdfasdfR0PxE` >>/root/.ssh/known_hosts
Which gives the error:
Code:
-bash: command substitution: line 1: unexpected EOF while looking for matching `"'
-bash: command substitution: line 2: syntax error: unexpected end of file
-bash: /root/.ssh/known_hosts: Permission denied
Which means it sounds like its trying to execute /root/.ssh/known_hosts instead of writing to it.

TIA
 
Old 11-27-2009, 09:36 PM   #2
18Googol2
Member
 
Registered: Oct 2008
Distribution: FreeBSD, RedHat, Centos, Solaris, AIX
Posts: 31

Rep: Reputation: 17
This should work:

Code:
ssh root@server1 'echo 55.55.55.55 ssh-rsa AAAABasdfaser45234234asdfasdfR0PxE >> /root/.ssh/known_hosts'
 
Old 11-27-2009, 09:51 PM   #3
abefroman
Senior Member
 
Registered: Feb 2004
Location: Chicago
Distribution: CentOS w/Cpanel
Posts: 1,134

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by 18Googol2 View Post
This should work:

Code:
ssh root@server1 'echo 55.55.55.55 ssh-rsa AAAABasdfaser45234234asdfasdfR0PxE >> /root/.ssh/known_hosts'
Thanks, but it still says permission denied, I tried it with ' and `
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] append command output to file by giving command in terminal sumeet inani Linux - Newbie 4 07-03-2009 10:36 AM
How to prevent others from remotely logging into my pc through ssh command? CPurnima Linux - Newbie 7 11-26-2008 08:10 AM
from Win XP, remotely execute a command on Linux using ssh lothario Linux - Software 3 06-21-2008 05:59 PM
Running a shell script remotely via 'ssh <hostname> <command>' davee Linux - General 4 10-09-2005 01:38 AM


All times are GMT -5. The time now is 05:04 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration