You may be working on SSH everyday, logining in and out, switching remote machines, change work locations (if you are working on a laptop), over and over. Each time you login into a machine, you have to wait for the command prompt for several seconds, input user name and password and kick yourself into the shell finally. Don’t you thinking it’s too time consuming to repeat the same actions? For me, I can not bear inputing the same password everyday. Here are some tricks to boost your productivity when working with SSH.
OpenSSH has a great feature “key-based authorization” which uses RSA/DSA key pair to do authorization instead of password. With the help of it, login can be done automatically.
Here are the steps:
~/.ssh. If you find a fine with name id_dsa.pub or id_rsa.pub, you are done since the key pair is ready to use. Otherwise, create it simply by typing ssh-keygen and following the instructions. Keep in mind that there are two kinds of key pairs, RSA or DSA. I always use RSA. You can choose one on your own. If you choose RSA with other options as default, you will get id_rsa and id_rsa.pub in ~/.ssh. The former file is the private key and latter one is the public key.~/.ssh is private. I want to emphasize that here that the private key, i.e. id_rsa, is the equivalent with your password since people who can access this file can login the remote machine easily as they got your password! So make it private first.chmod 700 ~/.ssh
scp ~/.ssh/id_rsa.pub user@remote.machine.com:~/my_key.pub
~/.ssh/authorized_keys on the remote machine.cat my_key.pub >> ~/.ssh/authorized_keys
ssh user@remote.machine.comon your local machine. If it works, remove the public key on the remote machine.
cat ~/.ssh/id_dsa.pub | ssh -l user remote.machine.com ‘cat >> ~/.ssh/authorized_keys’
Even auto login is set up, in some cases you have to wait for several seconds before the shell prompt bombs out. Still frustrating, right? In some worse cases, you have wait more than 10 seconds or even longer! Why? Each time you connect a remote machine, sshd would like to use your IP address to apply reverse DNS lookup to determine your hostname. If the DNS server goes slow, it may take seconds to return the results. The longer the lookup takes, the longer you have to wait.
Two tricks can be applied to solve this problem:
/etc/hosts on the remote machine and add the IP address of your local machine to it with an appropriate hostname. So if you login the system, your IP address is resolved locally, which is definitely faster./etc/ssh/sshd_config and add one line:UseDNS noRestart the sshd server then. If everything goes well, you will see the save of time.
Both tricks require root privilege. If do not have root access, ask your administrator to help you.
Use ssh -v or ssh -vvv to output debug information and diagnose the problem.