Re: Question about ssh no login



On 2007-04-28, sk8terg1rl <sk8terg1rl_2006@xxxxxxxxxxx> wrote:
Hi group,

I've implemented ssh no logins between 2 computers. Basically it
involved generating a public & private key pair with no passphrase and
appending the public keys to "authorized_hosts2" in the ".ssh" folder
for either machine.

How do I run commands in the remote machine from the local machine's
bash?

I tried a simple script on the local machine containing "ssh
remotemachine@xxxxxxxxxxxxxxx; ls; exit". It logs in fine but ignores
the rest of the script.

Any input please?

The script as you wrote it does the following on the local
machine:

ssh remotemachine@xxxxxxxxxxxxxxx
ls
exit

I suspect you don't see the 'ls' and 'exit' executed
locally, because the ssh process is waiting to read commands
on its stdin, because the ssh command you gave sets it up to
open an interactive session, using its stdin and stdout if I
understand correctly.

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 remotemachine@xxxxxxxxxxxxxxx <<EOF
ls
exit
EOF

If I'm right, this will cause the ssh process to read "ls"
followed by "exit" on its stdin and execute them on the
remote machine.

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:

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

One of the chmod commands might not be needed.

HTH

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



Relevant Pages

  • Re: Remote Execution Through FTP
    ... > I need to send some file from my local machine to a remote machine ... > generation mechanism in SSH. ... then you can script this quite easily using public key's to authenticate. ... Make sure the permissions on the .ssh directory and all the files in it are ...
    (comp.unix.admin)
  • Re: Remote Execution Through FTP
    ... >> I need to send some file from my local machine to a remote machine ... >> All these operations i have to do in script. ... >> generation mechanism in SSH. ... > the authorized_keys file in the .ssh directory. ...
    (comp.unix.admin)
  • Re: Remote Execution Through FTP
    ... >>> I need to send some file from my local machine to a remote machine ... >>> All these operations i have to do in script. ... >>> generation mechanism in SSH. ... >> the authorized_keys file in the .ssh directory. ...
    (comp.unix.admin)
  • [opensuse] BASH - Need help with ssh remote directory test?
    ... I have run into another bash caveat I don't understand. ... Evidently, the ssh ... The relevant portions of the script are: ... call is making it exit. ...
    (SuSE)
  • Re: urgent newbie question : ssh : problem with variable inside ssh session
    ... > ssh host << EOF ... That's not the whole script, ... > the it is created on the remote machine but cannot be ... If you run a script on your local machine, your local shell will try ...
    (Debian-User)