linux SSH免登录

来源:互联网 发布:linux file命令 x86 编辑:程序博客网 时间:2024/04/30 17:21

资源:

A机器(免登录至其他linux机器上) 。

B为远程机器,假如ip为172.18.100.133 。

SSH端口为10022默认为22。


A和B的系统都是Linux(相同用户webapp,默认路径为/home/webapp)。


在A机器上操作如下命令(通过webapp登录操作):


$ ssh-keygen -t rsa(连续三次回车,即在本地生成了公钥和私钥,不设置密码)
$ ssh -p 10022 webapp@172.18.100.133 "mkdir .ssh;chmod 0700 .ssh"
$ scp -P 10022 ~/.ssh/id_rsa.pub webapp@172.18.100.133:.ssh/id_rsa.pub


在B 机器上操作的命令(通过webapp登录操作):


$ touch /home/webapp/.ssh/authorized_keys
$ chmod 600 ~/.ssh/authorized_keys
$ cat ~/.ssh/id_rsa.pub  >> ~/.ssh/authorized_keys


在A机器上:
$ ssh -p 10022 webapp@172.18.100.133 (不需要密码, 登录成功)
0 0
原创粉丝点击