Linux免密碼登入設定 ssh-keygen
linux系統配置免密碼的方式:
1:ssh-keygen -t rsa
生成金鑰
[[email protected] ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
5d:3c:0c:d1:c7:4d:b8:8c:7e:35:66:89:ae:75:fa:e8
The key's randomart image is:
+--[ RSA 2048]----+
| oo . +.|
| +. + .|
| =+...|
| . ..oo=.|
| S ... o..|
| .o.. |
| o.o |
| . .. |
| .E.. |
+-----------------+
2:ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
把本機的公鑰追到116.255.34.112的 .ssh/authorized_keys 裡
[[email protected] ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
3:測試
[[email protected] ]$ ssh 116.255.34.112
Last login: Thu Aug 7 16:37:55 2014 from 116.255.34.110
[
4:如果ssh的埠不是22,可用下面命令
[[email protected] ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub '-p 2200 [email protected]'
5.如線上伺服器會對ssh服務改成非22埠,這時候,在伺服器之間建立雙機互信的情況下,若使用ssh-copy-id命令,不經過特定的語法,會報錯。
比如:
[[email protected] ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub '-p 20460 [email protected]*.*.*.*'
Now try logging into the machine, with "ssh '-p 10022 [email protected]*.*.*.*'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.