[]里表示具体可变
本地执行:
[root@centos7 ~]# ssh-keygen -t rsa
一直回车
[root@centos7 ~]#ls .ssh/
会生成公钥id_rsa.pub和私钥id_rsa
[root@centos7 ~]#ssh-copy-id root@47.94.237.171
或者也可以用下面呢这个方法,好理解但是烦
[root@centos7 .ssh]# scp id_rsa.pub root@47.94.237.171:/root ##======远程目的是为了将id_rsa.pub下内容cp到云的authorized_keys中
登陆到云上,写到那个中
这样登陆云就不需要密码了
[root@centos7 ~]#ssh root@47.94.237.171
Last login: Thu Dec 21 10:44:43 2017 from 47.94.237.171
但是我想直接输入ssh www就可以无密钥登陆。www是47.94.237.171的主机名
[root@centos ~]# cd .ssh/
[root@centos7 .ssh]# ls
authorized_keys config known_hosts
[root@centos .ssh]# cat config
#Host [hostname]
# User [username]
# HostName [ip]
Host www
User root
HostName 47.94.237.171
Host git.ionicjs.com ------///不知道什么,可不写
IdentityFile /root/.ssh/id_rsa -----可不写
一下测试是ok的:
[root@wt-01 ~]# ssh www
Last failed login: Thu Dec 21 11:03:36 CST 2017 from 47.94.237.171 on ssh:notty
There were 2 failed login attempts since the last successful login.
Last login: Thu Dec 21 10:38:35 2017 from 120.7.4.2
[root@wt--4 ~]#
我想直接输入:www就可以访问:
这个通过别名alias设置
在配置文件/etc/bashrc或者/etc/profile或者~/bash_profile中写入
alias www=‘ssh root@47.94.237.171’
然后source一下就可以了。
完
参考网站:blog.csdn.net/wangjunjun2008/article/details/20037101