From charlesreid1

Revision as of 05:22, 7 October 2010 by Admin (talk | contribs) (Created page with "= Passwordless Login = These instructions will enable you to log in to MachineB from MachineA without entering your password. '''DO THIS STEP ONCE:''' Generate a public and pr...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Passwordless Login

These instructions will enable you to log in to MachineB from MachineA without entering your password.

DO THIS STEP ONCE:

Generate a public and private key. Use the DSA encryption algorithm. To do this, execute the command:

[MachineA] $ ssh-keygen -t dsa

You'll be prompted for a passphrase that must be entered every time you use your public key. This operation will create two files, ~/.ssh/{id_dsa,id_dsa.pub}.

The file id_dsa is your private key - DO NOT SHARE YOUR PRIVATE KEY WITH ANYONE!

Now remote-login to MachineB and paste the public key for MachineA into MachineB's list of authorized keys:

[MachineB] $ vi ~/.ssh/authorized_keys

and paste the contents of MachineA's public key.

END OF STEP TO DO ONLY ONCE.


To login to MachineB from MachineA without entering your password, perform the following steps:

[MachineA] $ ssh-agent   # <-- copy and paste the output of this command into a terminal;
                         #      this will set 2 environmental variables
[MachineA] $ ssh-add

You will be prompted for your public key passphrase once per session, and once you enter it, you will have passwordless access to MachineB from MachineA.


These steps are somewhat cumbersome, and can be shortened to a much more convenient bash function as follows. I want to create a bash function on MachineA so that when I type:

[MachineA] $ MachineB

I will instantaneously be logged in to MachineB. To do this, I will create a function in my ~/.bashrc (or somewhere similar, I use a ~/.aliases file). This will look as follows:

alias MachineB="MachineB"
function MachineB() {
  # put environmental variables in ssh.file
  ssh-agent > ~/ssh.file

  # execute this file, sending output to /dev/null
  chmod +x ~/ssh.file
  ~/ssh.file > /dev/null
#  echo $SSH_AGENT_PID
#  echo $SSH_AUTH_SOCK
  rm -f ~/ssh.file

  # ssh to MachineB
  ssh -Y user@MachineB.com
}

Voila!