User Tools

Site Tools


software:ssh_config

This is an old revision of the document!


The ~/.ssh directory can do a lot more than just keep your SSH keys. Use it correctly, and SSH turns from a chore to something you use as transparently as a mountpoint.

Remote Execution

If your goal is to just execute one command on the remote, you can do better than log in - execute - log out: You can pass the command to execute directly to SSH:

ssh user@example.com "ls ~"

This prints the contents of your remote home directory to your local shell.

~/.ssh/authorized_keys

If you copy the contents of your local ~/.ssh/*.pub file (i.e., the public part of your key pair) into the remote ~/.ssh/authorized_keys file, future connections to that remote will make use of pubkey authentification. You don't need to remember the remote's password, just the keyphrase for your local private key.

As for “how do I get my .pub file contents into that file, that can be done by remote execution of cat plus output redirection:

cat ~/.ssh/id_ed25519.pub | ssh user@example.com "cat >> ~/.ssh/authorized_keys"

~/.ssh/config

A much underappreciated gem is ~/.ssh/config. This can be used for by-host configurations of SSH. Try this:

Host MyHost
    Hostname MyHost.example.com
    User MyHostUser1234
    Port 8022

Instead of having to write MyHostUser1234@MyHost.example.com:8022, all you need to write now is MyHost.

Bottom Line

If you have set up your SSH environment correctly, copying a file from local to remote becomes as easy as scp <oldfile> MyHost:~/<newfile>.

software/ssh_config.1785132422.txt.gz · Last modified: by solar

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki