4.4、编辑 sshd_config 配置文件
事实上该配置文件不需要修改也能正常启动 sshd ,下面是该配置文件的简要中文解释。详细解释见《sshd_config 中文手册》 下载见 http://www.linuxidc.com/Linux/2011-10/45740.htm
Port 22 #默认端口
ListenAddress #监听的网络地址
AddressFamily #监听的IP地址类型
Protocol 2 #SSH协议的版本号,默认为1#主机私钥文件的位置
HostKey /usr/local/ssh/ssh_host_rsa_key
HostKey /usr/local/ssh/ssh_host_dsa_key在SSH-1协议下,以固定周期生成服务器密钥及大小。
KeyRegenerationInterval 1h
ServerKeyBits 1024SyslogFacility AUTH #指定日志子系统(facility)
LogLevel INFO #指定日志详细程度LoginGraceTime 2m #2分种内必须认证成功,0 无限制。
PermitRootLogin yes #是否允许 root 登录
StrictModes yes #连接请求前对相关文件权限检查。
MaxAuthTries 6 #指定每个连接最大允许的认证次数
MaxSessions 10 #最大允许保持多少个未认证的连接
RSAAuthentication yes #否允许使用纯 RSA 公钥认证,仅用于SSH-1。
PubkeyAuthentication yes #是否允许公钥认证,仅用于SSH-2。#用来登录的 RSA/DSA 公钥存放位置,
AuthorizedKeysFile .ssh/authorized_keysRhostsRSAAuthentication no #是否使用强可信主机认证,仅用于SSH-1。
HostbasedAuthentication no #同上,仅用于SSH-2。
是否在 RhostsRSAAuthentication 或 HostbasedAuthentication 过程中忽略用户的 ~/.ssh/known_hosts 文件
IgnoreUserKnownHosts no
是否在 RhostsRSAAuthentication 或 HostbasedAuthentication 过程中忽略 .rhosts 和 .shosts 文件。
IgnoreRhosts yesPasswordAuthentication yes #是否使用密码认证
PermitEmptyPasswords no #是否允许密码为空的用户远程登录
ChallengeResponseAuthentication yes #是否允许 challenge-response 认证Kerberos认证相关设置,可忽略
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no是否允许使用基于 GSSAPI 的用户认证。
#GSSAPIAuthentication no
是否在用户退出登录后自动销毁用户凭证缓存
#GSSAPICleanupCredentials yesAllowAgentForwarding yes #是否允许端口转发
AllowTcpForwarding yes #是否允许TCP端口转发
GatewayPorts no #是否允许远程主机连接本地的转发端口。X11Forwarding no #是否允许进行 X11 转发。
X11DisplayOffset 10 #指定X11 转发的第一个可用的显示区数字。
X11UseLocalhost yes #是否将X11转发服务器绑定到本地loopback地址PrintMotd yes #每次登录时打印 /etc/motd 文件内容
PrintLastLog yes #每次登录时打印最后一位用户的登录时间
TCPKeepAlive yes #是否向客户端发送 TCP keepalive 消息。UseLogin no #是否在交互式会话的登录过程中使用 login
UsePrivilegeSeparation yes #创建非特权子进程来进行权限分离。指定是否允许处理 ~/.ssh/environment 以及 ~/.ssh/authorized_keys 中的 environment= 选项。
#PermitUserEnvironment no是否对通信数据进行加密,还是延迟到认证成功之后再对通信数据加密。
#Compression delayed#ClientAliveInterval 0 #超时提醒,0 表示不发送"alive"消息提醒。
#ClientAliveCountMax 3 #允许发送多少个"alive"消息。默认值是 3 。
五、基于密钥的认证
5.1、在本地生成密钥对
ssh-keygen 默认使用rsa算法生成密钥,如果要使用dsa算法,则需要使用-t 指定比如($ ssh-keygen -t dsa)
1 2 |
cd ~/.ssh/ #进入.ssh目录 ssh-keygen -N '' #生成无密码的密钥对,然后会提示输入密钥名称 |
5.2、上传公钥至服务器
通过scp将公钥传复制到远程服务器.ssh目录下,并改名为authorized_keys
1 |
scp wangyan.pub wangyan@wangyan.org:.ssh/authorized_keys |
5.3、建立安全连接
如果本地.ssh目录下的私钥改名,那么链接失败或改为密码认证。
如果putty作为客户端,那么这个id_rsa需要经过PUTTYGEN.EXE转换一次以后才能使用
1 2 3 4 |
ssh wangyan@wangyan.org sftp wangyan@wangyan.org scp wangyan@wangyan.org ...... |
六、SSH 帐号管理
1 2 3 4 5 6 7 8 |
passwd #修改当前用户密码 groupadd SSH #添加组 useradd -g SSH -s /bin/'bash' -d /home/user1 user1 #添加用户 passwd user1 #为用户user1创建密码 userdel user1 #删除用户user1 groupdel SSH #删除组SSH 停用帐号,VIM编辑密码文件,在用户名后添加 ":*" 。 vim /etc/shadow |
1 2 |
service sshd restart # 重启sshd ps -aux | grep sshd #查看是否运行成功 |
