What is SSH?

A protocol (and command) that encrypts communication for logging in to another computer over a network and running commands there. The server listens on TCP port 22 by default. Besides passwords, public-key authentication is widely used for authentication: the public key corresponding to the private key at hand is registered in ~/.ssh/authorized_keys on the server. Over the same connection, files can be transferred with scp or rsync, and ports can be forwarded.

Japanese name: SSH

SSH appears in 3 practice questions across 2 topics, including Linux and Command-Line Basics, Computer Networking Basics.

Field: Linux and Command-Line Basics

How public-key authentication works

A pair of a private key and a public key is created with ssh-keygen, and only the public key (the .pub file) is registered in authorized_keys on the server. When connecting, the client makes a signature with the private key and presents it to the server, which checks it with the registered public key, so the private key itself never travels over the network. The private key is protected with a passphrase, and leaving it with ssh-agent reduces the effort of entering it at every connection.

Verifying the server

On the first connection, ssh shows the fingerprint of the server's host key and, if accepted, records it in ~/.ssh/known_hosts. From then on, if a key different from the record is presented, it warns and stops, so an impersonating server can be noticed. If the warning appears without a reason such as the server having been replaced, the connection must not be continued.

Use in design work

Users log in with ssh from their PCs to the compute servers that run EDA tools, submit simulations and check results. Writing host aliases, user names, key files and jump servers (ProxyJump) in ~/.ssh/config makes it possible to connect with just ssh server1. Tools with a graphical interface are used in combination with X11 forwarding or remote desktop mechanisms.

Try it: questions about SSH

On a server reached over SSH, a long-running task was started with "./run.sh &", and when the connection was closed the task stopped too. Which of the following is the most appropriate way to start it so that it keeps running after the connection is closed?

  1. A./run.sh > run.log 2>&1 &
  2. Bnice -n 19 ./run.sh > run.log 2>&1 &
  3. Cnohup ./run.sh > run.log 2>&1 &
Show answer and explanation

Answer: C. nohup ./run.sh > run.log 2>&1 &

When the connection is lost, SIGHUP, which reports that the terminal has hung up, is sent to the shell, and shells such as bash also send SIGHUP to their jobs. The default action on receiving SIGHUP is to exit, so background jobs stop as well. nohup starts the command so that it ignores SIGHUP, and with its output directed to a file, the task keeps running after the connection is closed. If it is started from a terminal without redirecting the output, nohup writes the output to a file called nohup.out. Another common approach is to use a tool such as tmux or screen, which keeps the terminal session alive on the server and lets you reattach to it later.

FAQ

I cannot connect, and "Permission denied (publickey)" is shown. What should I check?

Check that the public key corresponding to the private key in use is registered in ~/.ssh/authorized_keys on the server, and that the user name is correct. If the permissions of ~/.ssh or authorized_keys on the server are too loose (writable by others), the key may not be used for safety, so set ~/.ssh to 700 and authorized_keys to 600, for example. With ssh -v, it shows which keys were tried.

How do I choose between scp and rsync?

Both can transfer files over ssh. scp suits simple copies, while rsync sends only the differences from the destination, so it is efficient for repeatedly synchronizing large directories or resuming interrupted transfers. Used as rsync -av --delete, it makes the destination match the source, but --delete removes files that exist only at the destination, so care is needed.

SSH in the explanations

Questions that mention SSH (3)

  1. On a server reached over SSH, a long-running task was started with "./run.sh &", and when the connection was closed the task stopped too. Which of the following is the most appropriate way to start it so that it keeps running after the connection is closed?
  2. You created a public-key authentication key pair with ssh-keygen on your own PC and want to connect to the server server1 with ssh without a password. Which of the following is the correct way to place the keys?
  3. Which correctly pairs protocols with the standard port numbers their servers use?

Books on Linux and Command-Line Basics Ad

As an Amazon Associate I earn from qualifying purchases.

Related terms

Shell File permissions Port number HTTP (Hypertext Transfer Protocol) DNS (Domain Name System) cron Environment variable Git grep Hard link

Back to the glossary