In this diagram, your terminal’s shell started the SSH client, which is connected to example.com on port 22. There, the SSH session started a shell, which runs your commands on the server.
Your computer.
You open a terminal, which starts a shell: Bash or Zsh.
You run a command, ls or any other: the shell starts it, and it runs on your computer.
ls works: it lists the files of the current directory, and prints them to your terminal.
It has finished, and exits.
Across the Internet, a server runs an SSH server, waiting for connections on port 22.
You run ssh jde@example.com: your shell starts the SSH client, which connects to port 22 on example.com.
The SSH server accepts the connection, and starts a new SSH session to take care of it.
It hands the connection over to the session, then goes back to waiting for the next one.
The session starts a shell on the server.
You type l. Your terminal hands it to the SSH client, which sends it over the connection at once, encrypted. On the server, the session hands it to the shell.
You type s: it travels the same way.
You press Enter, which travels too. Once it has arrived, the server’s shell runs ls, on the server.
ls works, on the server: it lists the files of the current directory there.
Its output travels back over the connection, and your terminal displays it.