linux远程命令工具 linux远程管理命令( 四 )


# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m #登录宽限期;
#PermitRootLogin yes #是否允许管理员直接登录;
#StrictModes yes
#MaxAuthTries 6 #最大密码输入错误次数;
#MaxSessions 10 #最大会话个数;
#RSAAuthentication yes #是否允许使用RSA机制来认证;
#PubkeyAuthentication yes
#--------中间不长改变的配置参数略----------
Subsystem sftp /usr/libexec/openssh/sftp-server #表示是否启动sftp功能;
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# ForceCommand cvs server
sshd认证方式:
1、基于口令的认证;
2、基于密钥的认证;
# ssh-keygen -t rsa 用rsa算法生成密钥,默认密钥为id_rsa(私钥), id_rsa.pub(公钥)
# ssh-keygen -f /path/to/somefile -P oldpassword 根据现有的密钥文件生成密钥
-f /path/to/somefile: 密钥文件保存在的位置;
-P '': 指定生成旧密钥时使用的密码;
方法一:把本地主机生成的公钥 id_rsa.pub使用scp复制到远程主机的上 , 在远程主机使用cat id_rsa.pub.ssh/authorized_keys追加该公钥信息,这样就可以实现基于密钥认证的ssh登录;
方法二:# ssh-copy-id -i .ssh/id_rsa.pub USERNAME@HOST
[root@www ~]# ssh-keygen -t rsa #用rsa算法生成密钥;
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): #指定密钥存放路径及名称,一般不用
#修改,直接回车;
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:
c2:f9:c2:3d:4d:ca:52:39:7a:a7:33:de:42:11:d3:8f root@
The key's randomart image is:
+--[ RSA 2048]----+
| . |
| o . |
| o o |
| . ...E . |
| + S.. |
| . B.= |
| =.B o |
| ++= |
| .o+. |
+-----------------+
[root@www ~]# ssh-keygen -f .ssh/id_rsa -P '' #根据现有密钥文件重新生成密钥;
Generating public/private rsa key pair.
.ssh/id_rsa already exists.
Overwrite (y/n)? y #提示是否确定要覆盖;
Your identification has been saved in .ssh/id_rsa.
Your public key has been saved in .ssh/id_rsa.pub.
The key fingerprint is:
bf:55:f0:0b:a5:ee:4e:4a:1d:d3:b1:0e:66:ee:55:9b root@
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| . o |
| * o |
| S O = .|
| . * B oo|
| o * +E |
| . B . |
| o.+ |
+-----------------+
#-----使用方法一:实现通过密钥文件完成身份验证(不需要输入密码)-----
[root@www ~]# scp .ssh/id_rsa.pub root@192.168.0.110:/root/ #使用spc命令复制公钥文件到远程
#主机的用户家目录下的.ss/路径下;
root@192.168.0.110's password: #输入登录远程主机的密码;
id_rsa.pub 100% 397 0.4KB/s 00:00 #提示复制成功;
[root@mailCentOS6 ~]# ls .ssh/ #验证确认文件复制成功;
id_rsa.pub known_hosts
[root@mailCentOS6 ~]# touch .ssh/authorized_keys #路径内没有自动验证密钥文件,创建一个;
[root@mailCentOS6 ~]# cat .ssh/id_rsa.pub.ssh/authorized_keys #把公钥追加到自动验证密钥文件;
[root@www ~]# ssh 192.168.0.110
Last login: Mon May 11 20:45:10 2015 from 192.168.0.111
[root@mailCentOS6 ~]# #OK了,看到了没有 , 不用输入密码我们就直接可以远程登录了?。?
#-----使用方法二:实现通过密钥文件完成身份验证(不需要输入密码)-----

推荐阅读