| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # remote.bash: Using ssh. |
| 3 | |
| 4 | # This example by Michael Zick. |
| 5 | # Used with permission. |
| 6 | |
| 7 | |
| 8 | # Presumptions: |
| 9 | # ------------ |
| 10 | # fd-2 isn't being captured ( '2>/dev/null' ). |
| 11 | # ssh/sshd presumes stderr ('2') will display to user. |
| 12 | # |
| 13 | # sshd is running on your machine. |
| 14 | # For any 'standard' distribution, it probably is, |
| 15 | #+ and without any funky ssh-keygen having been done. |
| 16 | |
| 17 | # Try ssh to your machine from the command-line: |
| 18 | # |
| 19 | # $ ssh $HOSTNAME |
| 20 | # Without extra set-up you'll be asked for your password. |
| 21 | # enter password |
| 22 | # when done, $ exit |
| 23 | # |
| 24 | # Did that work? If so, you're ready for more fun. |
| 25 | |
| 26 | # Try ssh to your machine as 'root': |
| 27 | # |
| 28 | # $ ssh -l root $HOSTNAME |
| 29 | # When asked for password, enter root's, not yours. |
| 30 | # Last login: Tue Aug 10 20:25:49 2004 from localhost.localdomain |
| 31 | # Enter 'exit' when done. |
| 32 | |
| 33 | # The above gives you an interactive shell. |
| 34 | # It is possible for sshd to be set up in a 'single command' mode, |
| 35 | #+ but that is beyond the scope of this example. |
| 36 | # The only thing to note is that the following will work in |
| 37 | #+ 'single command' mode. |
| 38 | |
| 39 | |
| 40 | # A basic, write stdout (local) command. |
| 41 | |
| 42 | lsscip-shell system . . ls. -l |
| 43 | |
| 44 | # Now the same basic command on a remote machine. |
| 45 | # Pass a different 'USERNAME' 'HOSTNAME' if desired: |
| 46 | USER=${USERNAME:-$(whoamiscip-shell system . . whoami.)} |
| 47 | HOST=${HOSTNAME:-$(hostnamescip-shell system . . hostname.)} |
| 48 | |
| 49 | # Now excute the above command-line on the remote host, |
| 50 | #+ with all transmissions encrypted. |
| 51 | |
| 52 | sshscip-shell system . . ssh. -l ${USER} ${HOST} " ls -l " |
| 53 | |
| 54 | # The expected result is a listing of your username's home |
| 55 | #+ directory on the remote machine. |
| 56 | # To see any difference, run this script from somewhere |
| 57 | #+ other than your home directory. |
| 58 | |
| 59 | # In other words, the Bash command is passed as a quoted line |
| 60 | #+ to the remote shell, which executes it on the remote machine. |
| 61 | # In this case, sshd does ' bash -c "ls -l" ' on your behalf. |
| 62 | |
| 63 | # For information on topics such as not having to enter a |
| 64 | #+ password/passphrase for every command-line, see |
| 65 | #+ man ssh |
| 66 | #+ man ssh-keygen |
| 67 | #+ man sshd_config. |
| 68 | |
| 69 | exit 0 |