Creating remote server nicknames with .ssh/config
Using the ~/.ssh/config file is an easy way to give your
remote machines nicknames and reduce the number of keystrokes needed
to login with ssh, rsync,
hg push/pull/clone, access
files via Emacs Tramp
(Transparent Remote (file) Access, Multiple Protocol),
or use any other SSH-based tool. You can also set other ssh options such
as IdentityFile, Port, or CompressionLevel.
For more information and a full list of options, check out the man page for ssh_config or
this article
by Kimmo Suominen.
Here is part of my ~/.ssh/config file. It defines the
nicknames turk, tyran, tuna, and tally for some EC2 servers I've been
working with.
Host turk User root HostName ec2-67-202-21-122.compute-1.amazonaws.com Host tuna User root HostName ec2-75-101-178-62.compute-1.amazonaws.com Host tyran User root HostName ec2-67-202-43-207.compute-1.amazonaws.com Host tally User root HostName ec2-67-202-59-207.compute-1.amazonaws.com
Now, wherever I would normally have typed
root@ec2-67-202-21-122.compute-1.amazonaws.com,
I can just type turk. Here are some examples.
SSH login
Old way:
ssh root@ec2-67-202-21-122.compute-1.amazonaws.com
New way:
ssh turk
rsync
Old way:
rsync -avz myproject root@ec2-67-202-21-122.compute-1.amazonaws.com:/srv
New way:
rsync -avz myproject turk:/srv
Mercurial
Old way:
hg push ssh://root@ec2-67-202-21-122.compute-1.amazonaws.com//srv/myproject
New way:
hg push ssh://turk//srv/myproject
Emacs Tramp
To use your ~/.ssh/config with Emacs Tramp, you will need
something like the following in your .emacs:
(tramp-set-completion-function "ssh"
'((tramp-parse-sconfig "/etc/ssh_config")
(tramp-parse-sconfig "~/.ssh/config")))
Old way:
C-x C-f /root@ec2-67-202-21-122.compute-1.amazonaws.com:/srv/myproject/myfile.py
New way:
C-x C-f /turk:/srv/myproject/myfile.py
scp
Old way:
scp etc/.screenrc root@ec2-67-202-21-122.compute-1.amazonaws.com:/root
New way:
scp etc/.screenrc turk:/root
Post a comment
About
I'm Eliot and this is my notepad for programming topics such as Python, Django, Ubuntu, Emacs, etc... more »
Search Blog
Tags
-
algorithms
(4)
-
aws
(8)
-
blogproject
(20)
-
c_cplusplus
(12)
-
cardstore
(8)
-
colinux
(2)
-
concurrency
(9)
-
conkeror
(2)
-
cygwin
(18)
-
datastructures
(15)
-
datetime
(3)
-
dell
(3)
-
django
(39)
-
emacs
(20)
-
files_directories
(10)
-
install_setup
(7)
-
javascript
(3)
-
keyboard
(6)
-
matplotlib
(5)
-
mercurial
(4)
-
nginx
(2)
-
preferences
(8)
-
processes
(3)
-
pyqt
(18)
-
python
(122)
-
ratpoison
(3)
-
regexes
(5)
-
rsync
(3)
-
softwaretools
(17)
-
sql
(13)
-
ssh
(7)
-
subversion
(6)
-
twisted
(6)
-
ubuntu
(60)
-
urxvt
(5)
-
vxworks
(25)
-
webservices
(4)
-
wmii
(7)
Blogroll
- Adam Gomaa
- Alex Clemesha
- Amir Salihefendic
- Armin Ronacher
- David Beazley
- David Ziegler
- Duncan McGreggor
- Gareth Rushgrave
- Glyph Lefkowitz
- Guido van Rossum
- Ian Bicking
- Jacob Kaplan-Moss
- James Bennett
- James Tauber
- Jesper Noehr
- Matt Harrison
- Nikolay Kolev
- Parand Darugar
- Peter Baumgartner
- Peter Bengtsson
- Rob Hudson
- Simon Willison
- Will McGugan