SSH connection
This page describes SSH connections in Tera Term Mac. Tera Term Mac connects with the OpenSSH ssh command that comes with macOS (/usr/bin/ssh), using the SSH2 protocol. SSH settings are converted to ssh options wherever possible.
Prerequisite
SSH has the following authentication methods:
- Password authentication
- Public key (and private key pair) authentication
- Using an authentication agent (macOS ssh-agent)
- keyboard-interactive authentication
This page describes the most commonly used methods.
Connection procedure
Choose [File] New connection... (⌘N) to open the connection dialog. Enter the host in "Host", choose SSH as "Service" and click "Connect".
Authentication uses the contents of the connection dialog and the prompts of the ssh command.
Which method is tried first can be set in [Setup] SSH Authentication... (passed to ssh as PreferredAuthentications).
When one method fails, ssh goes on to the next method the server allows.
- For password authentication, enter "User name" and "Password". If "Password" is left empty, ssh asks for the password in the terminal; type it there. If you enter the password, Tera Term Mac sends it automatically when the password prompt appears.
Note: the SSH packet that carries the password is encrypted, so the password is not sent in clear text as with TELNET. - For public key authentication, choose the private key file with the "Choose..." button next to "Private key file" (ssh -i). When empty, ssh uses its standard keys, such as the ones in ~/.ssh. The passphrase is asked in the terminal.
Note: only private key formats that OpenSSH can read are supported. Convert PuTTY (.ppk) keys to OpenSSH format with PuTTYgen or similar. - For keyboard-interactive authentication, the prompts from the server appear in the terminal; answer them there.
- To use an authentication agent, add your key to ssh-agent (ssh-add). On macOS you can also store the passphrase in the keychain (ssh-add --apple-use-keychain).
User name
The connection dialog is filled in with the user name according to the settings. With "Use logon username", the name of the user logged in to this Mac is used.
Non-ASCII characters such as Kanji can be used (RFC 4252). The server must also support them.
See also: Notes on using non-ASCII characters in user name or password
Password / passphrase
When ssh asks for a password or passphrase in the terminal, just type it into the terminal. The characters are not displayed.
- You can also paste with ⌘V.
Security warning
ssh_known_hosts file
When connecting, ssh checks the server's host key against the known_hosts file. The default is ~/.ssh/known_hosts, the same file used by ssh in the macOS Terminal. The file can be changed in [Setup] SSH....
Depending on the result, ssh shows the following in the terminal.
- No key of the host is registered: "The authenticity of host ... can't be established." with the fingerprint, and you are asked whether to continue. Typing yes registers the key and connects.
- The key differs from the registered one: "REMOTE HOST IDENTIFICATION HAS CHANGED!" is shown and ssh does not connect.
- The key matches the registered one: no warning is shown.
A warning may mean that you are connecting to an unintended server or that you are under a man-in-the-middle attack.
However, it also appears when you connect to a server for the first time, or when the server's host key has changed (for example after reinstalling the server). Compare the fingerprint shown in the warning with the correct fingerprint of the SSH server's host key.
After confirming that the host key really changed, run ssh-keygen -R hostname in the local shell (⌘G) to remove the old key, and connect again.
With OpenSSH, the server administrator can get the fingerprint of the host key with a command like:
ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub
SSHFP RR
Host keys can be verified with SSHFP RR (Secure SHell FingerPrint Resource Record) defined in RFC 4255. The setting in [Setup] SSH... is passed to ssh as the VerifyHostKeyDNS option.
The owner of a domain can register the fingerprint of the SSH server's host key as an SSHFP record in DNS. ssh fetches the SSHFP record and compares it with the host key of the server.
RFC 4255 says "SSHFP RRs not authenticated by DNSSEC must not be trusted". When the record cannot be verified with DNSSEC, ssh only reports the match and still asks for confirmation of a key that is not in known_hosts.
Generating keys
This section explains how to generate a public/private key pair for public key authentication. Choose [Setup] SSH KeyGenerator.... Keys are generated with the macOS ssh-keygen command.
In "Key type", choose RSA, DSA, ECDSA-256/384/521 or ED25519. Enter a key passphrase (like a password, but it may contain spaces and can usually be longer) and a comment, then click "Generate". Then click "Save public key" and "Save private key" to save the keys. The ~/.ssh folder is the usual place. Click "Close" when done.
Put the contents of the file with the "pub" extension (the public key) in the designated place on the server (usually append it to (home dir)/.ssh/authorized_keys; you can also use the ssh-copy-id command in the local shell). The file without an extension is the private key, which you specify when logging in.
Caution: never let anyone else know your private key, and manage it strictly. Be careful not to copy it to the server by mistake.