在做linux自动化运维的时候,服务器时常需要配置无密码的登录方式,下面就来说一下无密码登陆
-------------------------方法1-------------------------
1、做一个公钥,一个私钥
在帐户家目录有:id_rsa(私钥) id_rsa.pub(公钥)
ssh-keygen,一路回车,会出现以下文件
Your public key has been saved in /root/.ssh/id_rsa.pub. (公钥,远程拷贝给别人)
The key fingerprint is:(私钥,自己保存)
e1:bd:99:49:4f:64:49:6b:5b:3a:31:3a:a5:3d:d8:5d root@station106.uplooking.com
2、把公钥远程拷贝给远程机器并且改名成 scp /root/.ssh/id_rsa.pub 192.168.1.136:~/.ssh/authorized_keys
-------------------------方法2-------------------------
# ssh-keygen
# cat ~/.ssh/id_rsa.pub | ssh user@server "cat - >> ~/.ssh/authorized_keys"
-------------------------方法3-------------------------
忘记拼写authorized_keys这个单词了,怎么办?很简单,linux给我们提供了一个工具
用法:ssh-copy-id -i ~/.ssh/id_rsa.pub user@server
1、ssh-keygen,一路回车
2、ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.1.136
问题:
为了服务器安全,我们修改了端口默认的22后,怎么办?
用法:ssh-copy-id -i ~/.ssh/id_rsa.pub "-p 10022 user@server"
ssh-copy-id "-p port user@host" 这样就可以让ssh-copy-id使用不同的端口了。呵呵
还没有评论,快来抢沙发!