Host $ALIAS
User $USER
HostName $INTERNAL
ProxyCommand ssh $USER2@$PUBLIC -W %h:%p
Now laptop> ssh [email protected]
public> ssh dev@myworkstation
becomes laptop> ssh work
(I just realized that this slightly confused
article seems to accomplish the same by using a convoluted
setup of port-forwardings and netcat.)netcat worked fine.
[1]: https://news.ycombinator.com/item?id=4678117 ServerAliveInterval 240
ServerAliveCountMax 5Yeah, the article sets separately first
Host bar
...
and then Host behind.bar
...
But it can also be done by just one step: host behindbar
User <user-behindbar>
Hostname behindbar.domain
ProxyCommand ssh <user-bar>@bar.domain nc %h %p 2> /dev/null Host bos-??
HostName %h.mydomain.com
IdentityFile ~/.ssh/my-boston-key
Host nyc-??
HostName %h.mydomain2.com
IdentityFile ~/.ssh/my-nyc-key
and log in with e.g. "ssh bos-14". Host *.amazonaws.com
User ec2-user
IdentityFile ...
And then it is just ssh ec2-X-X-X-X.compute-1.amazonaws.comThanks though, I didn't know about the ?? syntax.
The patterns are similar to shell globs: * matches zero or more characters, ? matches exactly one.
scp $ALIAS:/var/log/mylogs/logfile ~/backups/logs/Nautilus / Connect to Server / Server Address: work/home/user
(here 'work' is the alias for the work computer)
Host 192.168.* *.foo.*.com *.bar.net alias compile-ssh-config='echo -n > ~/.ssh/config && cat ~/.ssh/*.config > ~/.ssh/config'
alias ssh='compile-ssh-config && ssh'
Compiles all your ~/.ssh/*.config files into a single ssh config file. It's simple and stupid and seems to do the trick.Maybe it is just me, but I prefer to dump all my custom commands and aliases into .zshrc so they are easy to backup/track/find.
One reason is so that invocations of ssh outside of the context of user invocation of ssh at the command line will also have these customizations included. This is especially important for ssh, which has emerged as a main security interoperability tool for Unix systems.
For example, if you use rsync, the tunneling and host alias conventions you set up in .ssh/ will carry over transparently to the ssh tunnel used by rsync.
Another example would be invocations of ssh in scripts (sh/bash scripts, even) that will not or might not read your .zshrc.
The idea of creating dependencies on a configuration profile inside a bash script is the exact opposite of what I would do.
I also could not rsync things to my local machine [bandwidth constraints] and would be rsyncing between remote machines, which being a shared environment, I would rely on explicit invocations instead of creating configurations/aliases.
Thank you for telling me how/why other people make different choices. I always do seem to have the blinders of my process is the only process I consider when commenting on HN. :)
Just specify the alias host name as configured in ~/.ssh/config and the user, identify file, and anything else you put there will be used as set.
File format: as many of the following blocks as you like
You can now ssh to that server as that user by doing "ssh $ALIAS" on the command line, without needing to specify the port or user with the usual command line arguments, or necessarily spell out the entire host name.