以密钥对认证代替用户名/口令认证那个
生成密钥对
ssh-keygen[2] -t type [-b bits]
生成 的密钥一般位于: ~/.ssh/id_rsa 和 ~/.ssh/id_rsa.pub
指定授权密钥
Example 2.2. 指定授权密钥
% mkdir -p ~/.ssh
% chmod 0700 ~/.ssh
% cp ~/id_rsa.pub ~/.ssh/authorized_keys
% chmod 0600 ~/.ssh/authorized_keys
/etc/ssh/sshd_config
PasswordAuthentication no
使用 ssh-agent
避免了登录 ssh 每次都要输入验证字
配置
需要~/.Xclients (or ~/.xinitrc) 中加入: exec ssh-agent bin/startx-continue[3]
加入
Example 2.3. 添加私钥
% ssh-add
Enter passphrase for /home/tony/.ssh/id_rsa: Identity added: /home/tony/.ssh/id_rsa (/home/tony/.ssh/id_rsa)
ssh-add 要我的验证字来对专用密钥进行解密并存储在 ssh-agent 的高速缓存中以备使用
不足
每次开机都要重新设置
限制 RSA 认证
authorized_keys内容:
ssh-rsa AAAAB3Nza............. tony@mail
修改为:
no-port-forwarding, command="/sbin/reboot",no-pty ssh-rsa AAAAB3Nza............. tony@mail
即 用户只允许 执行 '/sbin/reboot' 命令