免密码,用别名登录ssh

【来自春哥早先的资料,表示感谢。】

1.生成密钥对

$ ssh-keygen -t rsa
一路回车
$ cd ~/.ssh
$ ls
可以看到生成了id_rsa.pub, id_rsa。

2.把公钥传到服务器上

$ ssh-copy-id -i id_rsa.pub linhan@202.38.xx.xx
输入密码

3.测试无密码登录

$ ssh linhan@202.38.xx.xx
应该不需要密码

4.配置别名

$ cd ~/.ssh
$ vi config
输入如下内容:

GSSAPIAuthentication no
host scc
hostname 202.38.xx.xx
user linhan

以后如果需要添加多个远程账户,只要添加 host, hostname, user 三行即可。

5.测试别名

$ ssh scc
应该就能登录,以后 ssh, scp 出现主机名的地方都可以用 scc 代替。

6.config 文件中各字段说明

host            别名
hostname        主机名
port            端口号
user            用户名
identityfile    密钥文件的路径

发表评论

电子邮件地址不会被公开。 必填项已用*标注