Re: Question about ssh no login



On 2007-04-28, sk8terg1rl <sk8terg1rl_2006@xxxxxxxxxxx> wrote:
Hi Robert, thanks for your help.

On Apr 28, 12:17 am, "Robert M. Riches Jr." <spamtra...@xxxxxxxxxxx>
wrote:

Do you want the 'ls' and 'exit' to be executed on the remote
machine? If so, you need to send those commands to the ssh
processes with something similar to the following: (I
haven't tested this, so YMMV.)

ssh remotemach...@xxxxxxxxxxxxxxx <<EOF
ls
exit
EOF


It works, but I get the following message:
sk8terg1rl@home:~/.ssh> ./test
Pseudo-terminal will not be allocated because stdin is not a terminal.
[ls output follows]

sk8terg1rl@home:~/.ssh> cat test
ssh sk8terg1rl@xxxxxxxxxx << EOF
ls
exit
EOF

By the way, exactly what is "<< EOF" for? The above script still works
if I change either EOF to anything else (even non-matching) but stops
working if I remove the first EOF
./test: line 1: syntax error near unexpected token `newline'
./test: line 1: `ssh sk8terg1rl@xxxxxxxxxx << '

Someone else also pointed you to documentation on the usage
of hear-documents. While I haven't read that documentation,
it's probably worth studying.

Another option you might consider if you can't get the above
to work would be to write your script into a file, with
proper first line if desired/needed, scp the file to the
remote machine, and then execute the remote copy of the file
as a script, doing something like the following on the local
machine:

Yes, I noticed permissions aren't preserved upon scp. Thanks for
pointing that out.

Glad to help.

cat > local-script <<EOF
#!/bin/yourshell
ls
exit
EOF
chmod +x local-script
scp local-script remotemach...@xxxxxxxxxxxxxxx:/path/to/remote-script
ssh chmod +x remotemach...@xxxxxxxxxxxxxxx:/path/to/remote-script
ssh remotemach...@xxxxxxxxxxxxxxx:/path/to/remote-script

After a bit of testing, your chmod command should read:
ssh remotemachine@xxxxxxxxxxxxxxx chmod 777 /path/to/remote-script

Otherwise by doing this:
ssh chmod 777 remotemach...@xxxxxxxxxxxxxxx:/path/to/remote-script

You get the error:
ssh: chmod: Name or service not known

I would recommend 'chmod +x' rather than 'chmod 777' for
security reasons. If there is an unfriendly user on the
remote machine, with 'chmod 777' that user could change your
script before you run it and gain control of your account.

--
Robert Riches
spamtrap42@xxxxxxxxxxx
(Yes, that is one of my email addresses.)
.



Relevant Pages

  • Checking for existence of command prior to execution
    ... alone in an interactive shell it works though. ... it will fail if I add ssh to the list of commands which is ... aliased by the tcsh that is calling the above script. ...
    (comp.os.linux.misc)
  • Re: [PHP] SSH and php
    ... % Is it possible to run a SSH command from php? ... it's possible to run any command from php. ... % Doing a quick search on google for "SSH commands" and "SSH help" returned ...
    (php.general)
  • Re: r command security
    ... > My write-up was to clean up trust relationships in the rhost.equiv file and ... Instead, I recommended using ssh. ... > system administrators didn't buy into this because they have to use these ... Some software needs r commands to work and cannot be changed to use ...
    (comp.security.unix)
  • Re: free/cheap Windows SSH client that supports login scripts?
    ... connect, the commands will run. ... to a given server running SSH and then log straight into the mysql ... SecureCRT is so much nicer than anything else out there, ... cheap if you are a heavy ssh user. ...
    (comp.security.ssh)
  • Re: how to connect to a remote machine using python........
    ... Some python ssh packages are available if you are wanting to execute ... commands on a machine that has ssh. ... you could run a Python-based web server from a simple ...
    (comp.lang.python)