SSH#
Lepton has an SSH client built on OTP's ssh. Use it to clone and push private GitHub repositories with git, to log in to your own servers, and to run commands on them.
Set up GitHub in four commands#
ssh-keygen # creates ~/.ssh/id_ed25519 and id_ed25519.pub
gh ssh-key add # uploads the public key (or paste it at github.com/settings/ssh/new)
ssh -T git@github.com # "Hi you! You've successfully authenticated..."
git clone git@github.com:you/private-repo.git
gh ssh-key add needs a token with the admin:public_key scope (see gh). Without one, print the key with cat ~/.ssh/id_ed25519.pub and add it on GitHub's SSH keys page. gh ssh-key list shows the keys on your account.
After that, git fetch, pull and push use the key for every git@github.com: remote. See git over SSH for switching existing clones and for gh repo clone.
On the live ISO your key disappears at shutdown, so add it to GitHub only from an installed system, which keeps /root/.ssh. Give Lepton its own key rather than copying the one from your Mac. You can then remove it from GitHub on its own.
Keys#
ssh-keygen creates an ed25519 key pair in OpenSSH format: the private key is mode 600 and the public key goes next to it with a .pub suffix.
ssh-keygen -C "me@lepton" # comment (default root@HOSTNAME)
ssh-keygen -f ~/.ssh/work_ed25519 # another file
ssh-keygen -l -f ~/.ssh/id_ed25519 # fingerprint
ssh-keygen -y -f ~/.ssh/id_ed25519 # print the public key
ssh and git try ~/.ssh/id_ed25519, id_ecdsa and id_rsa, plus any IdentityFile from ~/.ssh/config or -i FILE. Keys made by OpenSSH elsewhere work too, as long as they have no passphrase: Lepton can't decrypt passphrase-protected keys yet, and says so when it finds one.
Known hosts#
Before sending your key, ssh checks the server's host key against:
~/.ssh/known_hosts(plain and hashed entries,[host]:portfor other ports);/etc/ssh/ssh_known_hosts, which ships with GitHub's published keys, sogithub.comis trusted out of the box.
The first connection to any other host shows its fingerprint and asks before adding it, as OpenSSH does. git can't ask, so it stops with the fingerprint and two ways to trust the host: run ssh HOST once, or add the key yourself:
ssh-keyscan git.example.com >> ~/.ssh/known_hosts # check the fingerprint first
ssh-keygen -R git.example.com # forget a host
A host whose key has changed is always refused, with a warning.
The ssh command#
ssh me@server # interactive shell on a remote terminal
ssh server uptime # run one command; its exit status is ssh's
ssh -p 2222 -i ~/.ssh/work_ed25519 me@server
echo hello | ssh server cat # piped input goes to the remote command
ssh -o StrictHostKeyChecking=accept-new server true
An interactive session uses the full terminal and follows window resizes (serial terminals too). Type ~. at the start of a line to disconnect. -T skips the terminal, and -t asks for one even with a command.
~/.ssh/config#
Host blocks with patterns (*, ?, !negation) and the first value wins, as in OpenSSH. These keywords are read:
| Keyword | Meaning |
|---|---|
HostName | the real host name or address (%h is the alias) |
User | login name (default root) |
Port | port (default 22) |
IdentityFile | a key to try; several add up |
StrictHostKeyChecking | ask (default), accept-new/no to add new hosts silently, yes to refuse them |
UserKnownHostsFile | instead of ~/.ssh/known_hosts |
Host gh
HostName github.com
User git
IdentityFile ~/.ssh/github_ed25519
Aliases work everywhere, including in git remotes: git clone gh:you/repo.git.
Not supported#
Logging in with a password (keys only), passphrase-protected keys, ssh-agent, agent and port forwarding, scp/sftp, and running an SSH server on Lepton.
Commands on this page#
| Command | What it does | Usage |
|---|---|---|
ssh | OpenSSH-compatible client: remote shells and commands, keys from ~/.ssh | ssh [-p PORT] [-i KEY] [-l USER] [-o StrictHostKeyChecking=VALUE] [-T|-t] [USER@]HOST [COMMAND...] |
ssh-keygen | create an SSH key, show fingerprints, forget a host | ssh-keygen [-t ed25519] [-f FILE] [-C COMMENT] | -l -f FILE | -y -f FILE | -R HOST |
ssh-keyscan | print a host's SSH public keys (known_hosts lines) | ssh-keyscan [-p PORT] [-t TYPES] HOST... |