Difference between revisions of "Power User Tools"
(Created page with "=Managing configs with <code>vcsh</code> and <code>mr</code>=") |
(→auto-reconnect) |
||
| (10 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | =Managing configs with <code>vcsh</code> and <code>mr</code>= | + | =Managing configs with <code>vcsh</code>= |
| + | |||
| + | <code>vcsh</code> [https://github.com/RichiH/vcsh] is a utility that allows you to create multiple git repositories to store configuration files in your home directory. | ||
| + | It solves the problem of having to use symlinks, and is a very nice tool. It works well with another tool named <code>mr</code> [https://github.com/joeyh/myrepos] that allows | ||
| + | you to synchronize all of your config repos with a single command. | ||
| + | |||
| + | ==Common Tasks== | ||
| + | |||
| + | ===Adding new repo=== | ||
| + | |||
| + | Let say you want to add a repo for tracking your zsh configuration. | ||
| + | First, create a gitignore file for the repo so you can just do <code>git add .</code> | ||
| + | |||
| + | > vim ~/.gitignore.d/zsh | ||
| + | ... | ||
| + | |||
| + | Add the following lines | ||
| + | |||
| + | /* | ||
| + | !/.zsh | ||
| + | |||
| + | |||
| + | Now create the repository and push to a remote | ||
| + | |||
| + | > vcsh init zsh # create the repo | ||
| + | > vcsh zsh add . # add all files not masked by ~/.gitignore.d/zsh | ||
| + | > vcsh zsh commit # commit files | ||
| + | > vcsh zsh remote add origin ssh://user@host/repo/with/write/access # create remote repo | ||
| + | > vcsh zsh push --set-upstream origin master # push to the origin and setup tracking | ||
| + | |||
| + | =Reverse SSH= | ||
| + | |||
| + | The <code>ssh</code> command has a <code>-R</code> option that can be used to allow <code>ssh</code> access to a computer that does not have a public, static IP address (such as a computer behind a NAT at home) using another | ||
| + | computer that does have a public IP Address. | ||
| + | |||
| + | Assume you have two computers, <code>Public</code> and <code>Private</code>. <code>Public</code> has a public, static IP address, and you have <code>ssh</code> access to it. <code>Private</code> is a computer that sits behind your home router, and cannot be accessed from the outside. On <code>Private</code>, run the following command: | ||
| + | |||
| + | > ssh -R 2222:localhost:22 Public | ||
| + | |||
| + | This will log into <code>Public</code> as normal, but it will also setup port forwarding. Now any <code>ssh</code> connections to port <code>2222</code> on <code>Public</code> will be forwarded to port <code>22</code> on <code>Private</code>. You could also add the <code>-N</code> and <code>-f</code> options: | ||
| + | |||
| + | > ssh -f -N -R 2222:localhost:22 Public | ||
| + | |||
| + | The <code>-N</code> option tells <code>ssh</code> not to run any commands on the remote (so it will not open a shell), and <code>-f</code> will cause <code>ssh</code> start and run in the background. | ||
| + | ==auto-reconnect== | ||
| + | |||
| + | The above command will work, but if <code>ssh</code> is disconnected for some reason, you will have to rerun it. In fact, some <code>ssh</code> clients are configured to disconnect after a certain amount of inactivity. The <code>autossh</code>[http://www.harding.motd.ca/autossh/] utility will monitor an <code>ssh</code> connection and reconnect it if it is disconnected. To use <code>autossh</code>, run the following command | ||
| + | |||
| + | > autossh -M 0 -f -N -R 2222:localhost:22 Public | ||
| + | |||
| + | The <code>-M</code> option tells <code>autossh</code> which port to use for monitoring the connection. For more detailed (and advanced configuration), see this [https://www.everythingcli.org/ssh-tunnelling-for-fun-and-profit-autossh/ blog post]. | ||
Latest revision as of 20:55, 3 May 2017
Contents
Managing configs with vcsh
vcsh [1] is a utility that allows you to create multiple git repositories to store configuration files in your home directory.
It solves the problem of having to use symlinks, and is a very nice tool. It works well with another tool named mr [2] that allows
you to synchronize all of your config repos with a single command.
Common Tasks
Adding new repo
Let say you want to add a repo for tracking your zsh configuration.
First, create a gitignore file for the repo so you can just do git add .
> vim ~/.gitignore.d/zsh ...
Add the following lines
/* !/.zsh
Now create the repository and push to a remote
> vcsh init zsh # create the repo > vcsh zsh add . # add all files not masked by ~/.gitignore.d/zsh > vcsh zsh commit # commit files > vcsh zsh remote add origin ssh://user@host/repo/with/write/access # create remote repo > vcsh zsh push --set-upstream origin master # push to the origin and setup tracking
Reverse SSH
The ssh command has a -R option that can be used to allow ssh access to a computer that does not have a public, static IP address (such as a computer behind a NAT at home) using another
computer that does have a public IP Address.
Assume you have two computers, Public and Private. Public has a public, static IP address, and you have ssh access to it. Private is a computer that sits behind your home router, and cannot be accessed from the outside. On Private, run the following command:
> ssh -R 2222:localhost:22 Public
This will log into Public as normal, but it will also setup port forwarding. Now any ssh connections to port 2222 on Public will be forwarded to port 22 on Private. You could also add the -N and -f options:
> ssh -f -N -R 2222:localhost:22 Public
The -N option tells ssh not to run any commands on the remote (so it will not open a shell), and -f will cause ssh start and run in the background.
auto-reconnect
The above command will work, but if ssh is disconnected for some reason, you will have to rerun it. In fact, some ssh clients are configured to disconnect after a certain amount of inactivity. The autossh[3] utility will monitor an ssh connection and reconnect it if it is disconnected. To use autossh, run the following command
> autossh -M 0 -f -N -R 2222:localhost:22 Public
The -M option tells autossh which port to use for monitoring the connection. For more detailed (and advanced configuration), see this blog post.