SSH w/ command in authorized_keys apparently needs pty


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SSH w/ command in authorized_keys apparently needs pty
# 1  
Old 07-09-2011
SSH w/ command in authorized_keys apparently needs pty

I'm trying to have an unattended remote PC log some data on home PC.
man sshd says I should be able to put a command in authorized_keys.
This is what I have on the remote machine. The key is a special key that isn't used elsewhere.

In my ~/.ssh/authorized_keys file on my desktop:
Code:
command="/bin/cat >> /home/ken/text/limited.log" ssh-dss AAAAB3Nz ...

Then to write the data, I issue this command on the remote machine, where desk_pc is the IP of my desk PC:
Code:
echo "$(date +%D)  Data ...." | ssh -x -i ~/.ssh/special_id_dsa desk_pc

I think this should work, but it doesn't.
I think my desktop it's trying execute the received text instead of cat it to the log file. This is displayed on the remote machine:
Code:
Pseudo-terminal will not be allocated because stdin is not a terminal.

-bash: line 1: 07/09/11: No such file or directory

Do I need a pty? How can I get stdin written to a file without a pty if I need one?
How do I get it to execute the /bin/cat command, not the received text?
# 2  
Old 07-09-2011
how about telling it to execute /bin/cat.

Code:
echo "$(date +%D)  Data ...." | ssh -x -i ~/.ssh/special_id_dsa desk_pc /bin/cat '>>' /path/to/remote/file

Note the single quotes around the >>, necessary to prevent it redirecting locally.

You only need a pty for interactive programs, cat isn't.
# 3  
Old 07-09-2011
I can do that with my regular key file. But I'm trying to limit this key so it can only cat data to the log file.

I won't be there to type in a passphrase or password, so security has to be a little weak. But I want to limit the weakness as much as possible.
# 4  
Old 07-09-2011
Have you considered reversing the order ?

That will be much easier to setup and more secure since the log generating machine will not be able to connect @ all to desk_pc.
While desk_pc will be able ssh to log machine and execute specific command/script only (as per key setup).
# 5  
Old 07-09-2011
The problem is, the remote site may have it's IP address changed, so I won't be able to ssh to it until I get the new IP address.

That's actually the main reason I want to do this. I can easily tell it my home IP address through a tiny file on a public site. But I have to give it the power to write something somewhere to tell me it's IP address.

This should be simple. And it almost works. But it doesn't.
# 6  
Old 07-09-2011
How about something like:
Code:
 command="echo \"$SSH_ORIGINAL_COMMAND\" >> /home/ken/text/limited.log" ssh-dss AAAAB3Nz ...

# 7  
Old 07-09-2011
No matter what I echo, it never writes to the log.
In fact, I tried to just touch the log, but it was not created.
The "command=" options seems to always be ignored.

Actually, that's not right. I put -v on ssh in my experimenting and found that ssh not only looks at the key I provided on the command line with -i, but it also considers the other key that is held in memory in unencrypted form by an ssh-agent process. It apparently chooses the one it wants, NOT the one I specified.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Ubuntu

Help me to revert the file /root/.ssh/authorized_keys

Hi, I copied the key of rsa.pub to authorized_keys using the below command cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys By mistake i have executed another command view cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys so now additional keys are copied.so please help me... (3 Replies)
Discussion started by: SA_Palani
3 Replies

2. Shell Programming and Scripting

Appending authorized_keys on multiple servers using ssh

Hi I have an ssh 'for' loop script to login and put a key on multiple servers. I need to append a file on each server but the command which works ok from the prompt does not work via the script. I have cat filename | ssh user@servername "cat >>append.file.name" I have tried to 'spawn' this in... (0 Replies)
Discussion started by: Grueben
0 Replies

3. Post Here to Contact Site Administrators and Moderators

Apparently my post is Homework/Classwork?

I previously posted a question in the Shell Scripting forum a few minutes ago. I recieved a message telling me I had breached a rule, apparently because my post was a homework infraction. Well, im currently trying to figure out how to use Raspberry Pi's (as im a starter) I asked one of my... (1 Reply)
Discussion started by: Waggie14
1 Replies

4. Programming

Race condition with PTY

I've been experimenting with pseudo-terminals and found something I don't quite understand. Writing an EOF character to the master end doesn't work quite as I expect. Once I've written any other data, the master pty seems to treat a single ^D as a seperator, i.e. writing "abcabc" would let cat do... (1 Reply)
Discussion started by: Corona688
1 Replies

5. UNIX for Dummies Questions & Answers

use of tty and pty files

Hi, According to my understanding tty files that are available in /dev directory are terminals that are given to different users. please help me understand what are /pty files, like are they drivers to the devices.. also is the default tty terminal given to a user.. (2 Replies)
Discussion started by: saharookiedba
2 Replies

6. UNIX for Advanced & Expert Users

monitoring SSH authorized_keys

Hi, We have around 200 SUN Servers in production environment and I have one box from where I manage all the servers. It's setup such that I can SSH from my box onto all the 200 servers with without supplying password. It is working fine but sometimes we notice the keys getting changed and asking... (1 Reply)
Discussion started by: prvnrk
1 Replies

7. Shell Programming and Scripting

monitoring SSH authorized_keys

Hi, We have around 200 SUN Servers in production environment and I have one box from where I manage all the servers. It's setup such that I can SSH from my box onto all the 200 servers with without supplying password. It is working fine but sometimes we notice the keys getting changed and asking... (0 Replies)
Discussion started by: prvnrk
0 Replies

8. Programming

good example for pty usage ?

i am looking for a good example to explain *why* someone should use pty's. (3 Replies)
Discussion started by: grumpf
3 Replies

9. AIX

How to monitor pty

Hi all, today I could not telnet in AIX 5.2 cause I received the error "telnetd: All network ports in use". To allow users to telnet again I increased the number of ptys from default 256 to the new number 512. To avoid the same problem in the future and for a better understanding, I need... (2 Replies)
Discussion started by: l-roner
2 Replies
Login or Register to Ask a Question