ssh有兩種鏈接方式vim
第一種:密碼認證鏈接方式安全
[root@admin ~]# ssh root@192.168.1.25 (服務端的ip回車提示以下)
The authenticity of host '192.168.1.250 (192.168.1.250)' can't be established.
RSA key fingerprint is 75:f9:55:3b:da:0d:38:b2:c6:1b:e9:18:96:97:8a:2e.
Are you sure you want to continue connecting (yes/no)?(這裏輸入yes保證密鑰回車)dom
Warning: Permanently added '192.168.1.250' (RSA) to the list of known hosts.
root@192.168.1.25's password:(輸入密碼回車)ssh
第二種:密鑰鏈接方式ide
[root@admin ~]# ssh-keygen(啓動密鑰鏈接方式)
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): (保持密鑰的地方默認是保spa
存在當前用戶目錄下如需ip
修改,輸入保持地址)
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:
e4:4d:4c:b7:e4:ec:07:d5:a7:f0:3c:a0:b0:1f:98:a1 root@admin
The key's randomart p_w_picpath is:
+--[ RSA 2048]----+
| . o .. |
| oo =oo o|
| ..*o.== ..|
| Eo+oo. .= |
| S.... .. |
| . . |
| |
| |
| |
+-----------------+ci
密鑰生成以後進入.ssh/目錄會看到get
[root@admin ~]# cd .ssh/
[root@admin .ssh]# ls
id_rsa id_rsa.pub known_hosts(id_rsa.pub)這個文件就是密鑰認證文件it
[root@admin .ssh]# ssh-copy-id -i id_rsa.pub root@192.168.1.25(把密鑰發送給服務端)
root@192.168.1.25's password:(輸入服務端密碼)輸入回車提示以下就成功了
Now try logging into the machine, with "ssh 'root@192.168.1.25'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
備註:若是系統裝或發生其它不能正常鏈接的狀況把.ssh/目錄下的文件刪除從新配置便可
若是想比較安全或控制用戶登陸進入cd /etc/ssh會看到
[root@admin .ssh]# cd /etc/ssh
[root@admin ssh]# ls
moduli ssh_host_dsa_key ssh_host_key.pub
ssh_config ssh_host_dsa_key.pub ssh_host_rsa_key
sshd_config ssh_host_key ssh_host_rsa_key.pub
ssh_config這個是客戶端配置文件不用管,sshd_config這個是服務端配置文件修改這個就行
用vim打開ssh_config
SyslogFacility AUTHPRIV
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin yes(把這個改爲no禁止用root登陸)
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
# To disable tunneled clear text passwords, change to no here!#PasswordAuthentication yes#PermitEmptyPasswords noPasswordAuthentication yes(打這個改爲no不能使用密碼驗證)