生活周遭

In My Circle

Tips: ssh记住密码,自动登录

, ,

ssh登录,每次都要敲密码,敲多了自然是烦。而且ssh的安全性,使它不能在任何配置文件中或者命令行参数中直接指出密码,所以只能不厌其烦的每次等待登录框出现,然后敲入密码。特别是使用ssh认证的cvs,svn之类的,更是影响工作情绪。ssh-agent就是用于解决这个问题的:

1. Creating authentication key

用ssh-keygen生成公/私钥对:
  beowulf% ssh-keygen -t rsa
  Generating public/private rsa key pair.
  Enter file in which to save the key (/u/kim/.ssh/id_rsa): [RETURN]
  Enter passphrase (empty for no passphrase): litt1e 1amp jumb3d
  Enter same passphrase again: litt1e 1amp jumb3d
  Your identification has been saved in /u/kim/.ssh/id_rsa.
  Your public key has been saved in /u/kim/.ssh/id_rsa.pub.
  The key fingerprint is:
  b7:18:ad:3b:0b:50:5c:e1:da:2d:6f:5b:65:82:94:c5 kim@beowulf.gw.com

记住你的passphrase(这里是little lamp jump3d)。其中~/.ssh/id_rsa.pub为公钥文件


2. Authorizing access

将公钥上传成目标机的~/.ssh/authorized_keys (ftp,scp都可以)
  beowulf% cd ~/.ssh
  beowulf% cp id_rsa.pub authorized_keys
  beowulf% scp -p ~/.ssh/authorized_keys kim@hrothgar:.ssh/
  kim@hrothgar’s password: YourPasswordHere
  authorized_keys               100% 1839     1.2MB/s   00:00 

其中需要输入目标机上你的用户密码(在此为hrothgar上的kim用户)。
这时,你使用ssh登录时,将会通过你identification的passphrase来登录了。
  beowulf% ssh hrothgar
  Enter passphrase for key '/u/kim/.ssh/id_rsa': litt1e 1amp jumb3d
  kim@hrothgar% 



3. Keeping authentication keys in memory

通过ssh-agent来记住认证,添加的方式见下一节。一般的做法是通过ssh-agent来启动一个shell,在该shell中使用:
  beowulf% ssh-agent $SHELL
  beowulf% 

我用的是Debian,在/etc/X11/Xsession.d/下面就又一个90xfree86-common_ssh-agent用于使用ssh-agent来启动X,这样,一进入X,ssh-agent就是可用的。如果你的系统里没有这样的设置,简单的做法就是用"ssh-agent startx"来启动X,如果你用的是xdm,gdm之类的,修改你的~/.xsession文件


4. Managing keys in memory

通过ssh-add添加keys。
  beowulf% ssh-add
  Enter passphrase for /u/kim/.ssh/id_rsa: litt1e 1amp jumb3d
  Identity added: /u/kim/.ssh/id_rsa (/u/kim/.ssh/id_rsa) 

然后,你就可以通过
  beowulf% ssh hrothgar
  kim@hrothgar% 

ssh登录而不需要密码了。

Firefox Space Bar无法滚屏的问题Tips: procmailrc规则中的中文处理

Comments

Anonymous Tuesday, April 17, 2007 10:14:05 AM

竹林漂泊 writes: 博主引用了别人的文章为什么没有说明呢? 我帮你加上吧:Getting started with SSH http://kimmo.suominen.com/docs/ssh/

Leira HuaLeira Friday, April 20, 2007 8:42:03 PM

教训的是~ 惭愧~
当时只是随手记下来,给同事看的,没有严谨翻译,而且看到原文也颇为辗转,没有去求证真正的源头,谢谢竹林漂泊兄,下次不会再犯了~。

Anonymous Wednesday, July 14, 2010 1:46:28 PM

Анонімний writes: Do you recognize that it is correct time to receive the personal loans , which can realize your dreams.

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies