Resources:
Some terminals (e.g. Alacritty) might be fucky to use (e.g. backspace generates weird characters, making it difficult to use at all) in conjunction with ssh. Quick fix:
TERM=xterm-256color ssh ...
The "proper" fix is to execute toe -a
on the remote machine to get the list
of supported terminals. Either install the terminfo of your terminal
onto the remote machine, or set the environment variable TERM
to
a supported one before connecting.
Use public key authentifcation when possible, it's generally more secure
and more convenient than passwords.
Use ssh-keygen
to generate key pairs:
To manage different configurations a variety of hosts,
create ~/.ssh/config
, where you can add
an entry for each host.
Here's an example configuration with a few neat options:
Host shorthand
# General options
HostName 127.0.0.1 # Either a remote IP or a domain, e.g. example.com
User root # The user to login as
Port 3029 # Default Port is 22
# To be able to use your public keys on the remote machine
ForwardAgent yes
# Force the usage of a specific "identity" / private key:
IdentitiesOnly yes
IdentityFile ~/.ssh/private_key_file
# Environment variables. If the server is extra fucky,
# specify special terminal info here:
SetEnv TERM=xterm
# To get a non-default shell (which is installed on the remote system):
RequestTTY force
RemoteCommand fish # Runs the "fish" shell
Then you can connect to the machine:
> ssh shorthand
# is now equivalent to:
> TERM=xterm ssh \
root@127.0.0.1 \
-p 3029 \
\
-A \
\
-i ~/.ssh/private_key_file \
\
-t \
fish
For key forwarding with ForwardAgent
,
the ssh-agent
needs to be running before
connecting:
# Run the agent for the duration of the given command,
# here we'll create a shell session (using "fish" shell)
> ssh-agent fish
# Add keys to agent
# Omit the argument to add all keys to the agent
> ssh-add ~/.ssh/public_key_file
# Connect, agent forwarding should work now
> ssh shorthand
If agent forwarding does not work, a workaround is to
generate a new password encrypted key-pair on the remote machine.
Alternatively, generate the encrypted key-pair locally and
upload it using scp
:
# Use -r to downloading / uploading a whole folder
# Upload from local machine to remote host
> scp ./localFile shorthand:/path/to/outputFolder
# Download from remote machine to local host
# (using the local machine)
> scp shorthand:/path/to/file ./
# If the host is not in the ssh config, use
# [user@]host[:port][/path]