Linux Labs

Networking / Stage 12 of 14

Diagnosing between two machines

Not running Starting usually ~20 s
Leave the lesson

Step 4 of 7 · theory · 4 min

Two real machines

In the module's labs the machines are real: the terminal is open on node1, and commands on node2 are run over SSH.

ssh node2 'command' logs in to node2, runs the command there and prints its output on your side. The quotes hand the whole string to the node2 shell: ssh node2 'sudo ss -ltn' shows the listeners of node2, while sudo ss -ltn without ssh shows those of node1. The line Warning: Permanently added 'node2'… that ssh prints at every login comes from how the practice pair is set up and does not affect the command.

A > redirection outside the quotes is carried out by your shell. ssh node2 'sudo nft list ruleset' > rules.txt saves the node2 rules to a file on node1. Inside the quotes, > writes the file on node2.

Write observations down with the machine's name: "on node1 the route is direct", "on node2 nginx listens on port 80". That shows which side has already been checked.

Check yourself 1 question

You are on node1 and type ssh node2 'sudo nft list ruleset' > rules.txt. Where does rules.txt appear?

  • The > is outside the quotes, so the node1 shell carried it out. The file would land on node2 with the > inside the quotes.

  • ssh prints the remote command's output on your side, and you can redirect it like any command's output.

  • One shell performs a redirection — the one that sees it. Outside the quotes that is the node1 shell.

A > outside the quotes is run by the shell where you typed ssh, on node1. To write the file on node2, put the redirection inside the quotes.

Key points

  • ssh node2 'command' runs the command on node2; whatever is in the quotes happens there.
  • A > outside the quotes writes the file on the machine where you typed ssh.
Ubuntu 24.04
Loading…