User Tools

Site Tools


user:kkrauss1:portfolio:lab46ssheasy

Making SSH'ing into lab46 from terminal simplified

  • If you are some one who logs into lab46 from a terminal screen consistently these are two steps to make the process easier.

Aliasing

  • The first thing we want to do is make it so we do not have to type “ssh “username”@lab46.corning-cc.edu” every time we want to log in, so we are going to alias that to a simpler command.
  • Make sure you are in your home directory and type “ls -a”, you should see a .bashrc file or something similar.(for example on my mint 12 machine it is called bash.bashrc).
  • Using an editor of your choice(make sure you have root privileges) open this file for editing.
  • In this file you want to add the following line:
    • alias newalias= 'ssh username@lab46.corning-cc.edu'
    • newalias is what you want to set equal to the ssh to lab46 command, aka an alias. I personally used “lab46”
    • username should be obvious, that is your username for lab46.
  • Now before you can just type lab46 and it will automatically enter the ssh to lab46 command, you must reload the .bashrc file
    • You can either reboot or be a true unix user and type
    • source .bashrc, this will automatically reload the .bashrc file

The power of Key's

  • If you go ahead and try your new alias, you will see hey with one short command I can connect to lab46, but darn it I still have to type that annoying little password, I don't want to do that! Well pay close attention boys and girls.
  • Make sure you are in your home directory, first we are going to generate a “Key”, so type:
  • ssh-keygen -t rsa
    • This is going to ask you where to store the key file, use the default.
    • It will also ask you for a passphrase which you can do but I chose not
  • If you look at the newly created .ssh directory and its contents you will see two files. id_rsa and id_rsa.pub, this is two key files, one is private and one is public. The public one is what you give to other hosts so it can check your private key and recognize who you are!
  • Now that we have created a key on our primary machine we now want to copy the public key, aka id_rsa.pub, to the host machine.
  • Go ahead and log into lab46 and type in that annoying password this time. Once you are logged in type the following:
  • scp user@primarymachine:~/.ssh/id_rsa.pub ~/.ssh/
    • user@primarymachine being your home machine, for testing I used my virtual server so used “root@vmserver05.student.lab”
    • You will be prompted for the password, remember its for your home machine at this point because you are logged into lab46.
  • You have now copied the file with your primary machines public key into the host machine.
  • cd into .ssh on lab46 and type:
  • cat id_rsa.pub » ~/.ssh/authorized_keys
    • What you have done here has copied your primary machines public key from the .pub file into an authorized_keys file.
    • The reason I had you append is just in case you have multiple machines with keys, you do not want to overwrite them.

Conclusions and notes

  • Guess what, you are done! Go ahead and type your aliased command into your primary machine. If everything was done right the alias will automatically ssh into lab46 and since you copied your primary machines public key info into the authorized_keys file on the host machine(lab46), it should be able to recognize you by your private key and bypass the password all together. Congratulations you just used knowledge to be lazy in the future, its awesome!. One thing to keep in mind when scp'ing your public key from primary machine to host is that your host might have generated keys for use in sshing into other machines. If this is the case you might not wish to overwite its public key so should copy your primary machines .pub file to a different file name.
user/kkrauss1/portfolio/lab46ssheasy.txt · Last modified: 2012/05/03 11:04 by kkrauss1