ssh密钥认证
密钥认证及sshd配置
Section titled “密钥认证及sshd配置”生成公钥和密钥
Section titled “生成公钥和密钥”$ ssh-keygen -t rsa$ cd .ssh/
将公钥添加到服务器
Section titled “将公钥添加到服务器”$ cat id_rsa.pub >> authorized_keys
sshd文件配置
Section titled “sshd文件配置”PermitRootLogin noPasswordAuthentication noRSAAuthentication yesPubkeyAuthentication yesAuthorizedKeysFile .ssh/authorized_keysChallengeResponseAuthentication no
SSH Server整体设定
Section titled “SSH Server整体设定”Port 22Protocol 2,1ListenAddress 192.168.0.100PidFile /var/run/sshd.pidLoginGraceTime 600Compression yes
主机私钥文件
Section titled “主机私钥文件”HostKey /etc/ssh/ssh_host_keyHostKey /etc/ssh/ssh_host_rsa_keyHostKey /etc/ssh/ssh_host_dsa_key
Version 1设定
Section titled “Version 1设定”KeyRegenerationInterval 3600ServerKeyBits 768
登录文件与daemon名称
Section titled “登录文件与daemon名称”SyslogFacility AUTHLogLevel INFO
PermitRootLogin noUserLogin noStrictModes yesPubkeyAuthentication yesAuthorizedKeysFile .ssh/authorized_keys
RhostsAuthentication noIgnoreRhosts yesRhostsRSAAuthentication noHostbasedAuthentication noIgnoreUserKnownHosts noPasswordAuthentication yesPermitEmptyPasswords noChallengeResponseAuthentication yes
Kerberos相关设定
Section titled “Kerberos相关设定”#KerberosAuthentication no#KerberosOrLocalPasswd yes#KerberosTicketCleanup yes#KerberosTgtPassing no
X-Window相关设定
Section titled “X-Window相关设定”X11Forwarding yes#X11DisplayOffset 10#X11UseLocalhost yes
PrintMotd noPrintLastLog yesKeepAlive yesUsePrivilegeSeparation yesMaxStartups 10
用户抵挡设定
Section titled “用户抵挡设定”DenyUsers testDenyGroups test
SFTP服务设定
Section titled “SFTP服务设定”Subsystem sftp /usr/lib/ssh/sftp-server
linux使用密钥登录
Section titled “linux使用密钥登录”- 将私钥拷贝到用户.ssh目录
- 执行
ssh-agent bash
- 执行
ssh-add 私钥文件
ssh登录太慢的解决方法
Section titled “ssh登录太慢的解决方法”SSH 登录太慢可能是 DNS 解析的问题。可以在 sshd 的配置文件(sshd_config)里取消 sshd 的反向 DNS 解析。
vi /etc/ssh/sshd_config找到UseDNS,修改为noUseDNS no重启SSH服务/etc/init.d/sshd restart
ssh-agent
Section titled “ssh-agent”eval "$(ssh-agent -s)"
[bash环境]
ssh-add -K ~/.ssh/id_rsa
~/.ssh/config
Host 111.111.111.111 HostName 111.111.111.111 #Port 22 User xxxxxx IdentityFile ~/.ssh/id_rsa_xxxx IdentitiesOnly yes
sshpass命令 – 用于非交互的ssh 密码验证
Section titled “sshpass命令 – 用于非交互的ssh 密码验证”sshpass命令用于非交互的 ssh 密码验证。
sshpass -p "password" ssh username@ipsshpass -p "password" ssh -p 8443 username@ipsshpass -p '123456' scp root@host_ip:/home/test/t ./tmp/