ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Linux SSH基本管理和配置文件的使用

Linux SSH基本管理和配置文件的使用

原创 Linux操作系统 作者:呱呱牛 时间:2016-05-21 18:38:07 0 删除 编辑
    SSH 是Secure Shell 安全外壳协议的简写,它是建立在应用层和链路层基础上的安全协议。
    传统的网络服务程序,如rsh、FTP、POP和Telnet其本质上都是不安全的;因为它们在网络上用明文传送数据、用户帐号和用户口令,很容易受到中间人(man-in-the-middle)攻击方式的攻击。就是存在另一个人或者一台机器冒充真正的服务器接收用户传给服务器的数据,然后再冒充用户把数据传给真正的服务器。
而SSH是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议。利用SSH协议可以有效防止远程管理过程中的信息泄露问题。通过SSH可以对所有传输的数据进行加密,也能够防止DNS欺骗和IP欺骗。
 SSHD服务使用SSH协议进行远程控制,或是在计算机之间传送文件。

SSH协议框架中最主要的部分是三个协议:

  1. 传输层协议(The Transport Layer Protocol):传输层协议提供服务器认证,数据机密性,信息完整性等的支持。
  2. 用户认证协议(The User Authentication Protocol):用户认证协议为服务器提供客户端的身份鉴别。
  3. 连接协议(The Connection Protocol):连接协议将加密的信息隧道复用成若干个逻辑通道,提供给更高层的应用协议使用。

一、服务安装和管理  

  •   SSHD使用以下四个rpm包进行安装:可以使用rpm 或yum的方式安装

点击(此处)折叠或打开

  1. rpm -qa | grep openssh
  2. openssh-server-5.3p1-94.el6.x86_64
  3. openssh-5.3p1-94.el6.x86_64
  4. openssh-clients-5.3p1-94.el6.x86_64
  5. openssh-askpass-5.3p1-94.el6.x86_64
  • OpenSSH 常用配置文件有两个/etc/ssh/ssh_config  和 /etc/ssh/sshd_config
        ssh_config 为客户端配置文件

        sshd_config 为服务器端配置文件

  • 服务启动和关闭

点击(此处)折叠或打开

  1. service sshd restart | start | stop | status | reload

点击(此处)折叠或打开

  1. /etc/init.d/sshd start | stop | restart | status | reload

二、服务语法和基本参数
SSH  [远程主机用户名]@[远程主机地址]

主要的参数选项

点击(此处)折叠或打开

  1. -1:强制使用ssh协议版本1; 
  2. -2:强制使用ssh协议版本2; 
  3. -4:强制使用IPv4地址; 
  4. -6:强制使用IPv6地址; 
  5. -A:开启认证代理连接转发功能;
  6. -a:关闭认证代理连接转发功能;
  7. -b:使用本机指定地址作为对应连接的源ip地址;
  8. -C:请求压缩所有数据; 
  9. -F:指定ssh指令的配置文件; 
  10. -f:后台执行ssh指令; 
  11. -g:允许远程主机连接主机的转发端口; 
  12. -i:指定身份文件; 
  13. -l:指定连接远程服务器登录用户名; 
  14. -N:不执行远程指令; 
  15. -o:指定配置选项; 
  16. -p:指定远程服务器上的端口; 
  17. -q:静默模式; 
  18. -X:开启X11转发功能; 
  19. -x:关闭X11转发功能; 
  20. -y:开启信任X11转发功能。

三、案例详解


  1. sshd_config中以#开头的服务都是默认开启的;


点击(此处)折叠或打开

  1. [root@mhxy162 ~]# cat /etc/ssh/sshd_config
  2. # $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $
  3. # This is the sshd server system-wide configuration file. See
  4. # sshd_config(5) for more information.
  5. # This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin
  6. # The strategy used for options in the default sshd_config shipped with
  7. # OpenSSH is to specify options with their default value where
  8. # possible, but leave them commented. Uncommented options change a
  9. # default value.
  10. #Port 22                         --可以通过SSH登录服务的端口
  11. #AddressFamily any
  12. #ListenAddress 0.0.0.0           --监听地址
  13. #ListenAddress ::                --IPV6地址
  14. # Disable legacy (protocol version 1) support in the server for new
  15. # installations. In future the default will change to require explicit
  16. # activation of protocol 1
  17. Protocol 2                   --SSH服务版本  1 or 2
  18. # HostKey for protocol version 1
  19. #HostKey /etc/ssh/ssh_host_key
  20. # HostKeys for protocol version 2
  21. #HostKey /etc/ssh/ssh_host_rsa_key
  22. #HostKey /etc/ssh/ssh_host_dsa_key
  23. # Lifetime and size of ephemeral version 1 server key
  24. #KeyRegenerationInterval 1h
  25. #ServerKeyBits 1024               --密码长度
  26. # Logging
  27. # obsoletes QuietMode and FascistLogging
  28. #SyslogFacility AUTH
  29. SyslogFacility AUTHPRIV
  30. #LogLevel INFO        --日志级别
  31. # Authentication:
  32. #LoginGraceTime 2m           --登录等待时间,默认是2分钟
  33. #PermitRootLogin yes         --是否允许root用户登录,设置no 禁止root登录
  34. #StrictModes yes
  35. #MaxAuthTries 6             
  36. #MaxSessions 10              --最大登录连接数据
  37. #RSAAuthentication yes                   --以下是公钥登录
  38. #PubkeyAuthentication yes
  39. #AuthorizedKeysFile .ssh/authorized_keys
  40. #AuthorizedKeysCommand none
  41. #AuthorizedKeysCommandRunAs nobody
  42. # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts         --记录尝试通过SSH登录的IP信息
  43. #RhostsRSAAuthentication no
  44. # similar for protocol version 2
  45. #HostbasedAuthentication no
  46. # Change to yes if you don't trust ~/.ssh/known_hosts for
  47. # RhostsRSAAuthentication and HostbasedAuthentication
  48. #IgnoreUserKnownHosts no
  49. # Don't read the user's ~/.rhosts and ~/.shosts files
  50. #IgnoreRhosts yes
  51. # To disable tunneled clear text passwords, change to no here!
  52. #PasswordAuthentication yes
  53. #PermitEmptyPasswords no                 --是否允许空密码登录
  54. PasswordAuthentication yes               --是否允许通过密码登录
  55. # Change to no to disable s/key passwords
  56. #ChallengeResponseAuthentication yes
  57. ChallengeResponseAuthentication no
  58. # Kerberos options
  59. #KerberosAuthentication no
  60. #KerberosOrLocalPasswd yes
  61. #KerberosTicketCleanup yes
  62. #KerberosGetAFSToken no
  63. #KerberosUseKuserok yes
  64. # GSSAPI options
  65. #GSSAPIAuthentication no
  66. GSSAPIAuthentication yes
  67. #GSSAPICleanupCredentials yes
  68. GSSAPICleanupCredentials yes
  69. #GSSAPIStrictAcceptorCheck yes
  70. #GSSAPIKeyExchange no
  71. # Set this to 'yes' to enable PAM authentication, account processing,
  72. # and session processing. If this is enabled, PAM authentication will
  73. # be allowed through the ChallengeResponseAuthentication and
  74. # PasswordAuthentication. Depending on your PAM configuration,
  75. # PAM authentication via ChallengeResponseAuthentication may bypass
  76. # the setting of "PermitRootLogin without-password".
  77. # If you just want the PAM account and session checks to run without
  78. # PAM authentication, then enable this but set PasswordAuthentication
  79. # and ChallengeResponseAuthentication to 'no'.
  80. #UsePAM no
  81. UsePAM yes
  82. # Accept locale-related environment variables
  83. AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
  84. AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
  85. AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
  86. AcceptEnv XMODIFIERS
  87. #AllowAgentForwarding yes
  88. #AllowTcpForwarding yes
  89. #GatewayPorts no
  90. #X11Forwarding no
  91. X11Forwarding yes
  92. #X11DisplayOffset 10
  93. #X11UseLocalhost yes
  94. #PrintMotd yes                 --打印提示信息  修改/etc/moth内容设置信息
  95. #PrintLastLog yes              --打印上次登录信息
  96. #TCPKeepAlive yes
  97. #UseLogin no
  98. #UsePrivilegeSeparation yes        --是否允许为权限较低用户提供服务,默认都是开启root身份登录,权限较高;启用该权限后,可以以登录用户身份使用SSH登录
  99. #PermitUserEnvironment no
  100. #Compression delayed
  101. #ClientAliveInterval 0
  102. #ClientAliveCountMax 3
  103. #ShowPatchLevel no
  104. #UseDNS yes                            --是否需要使用DNS  局域网登录慢时可以尝试关闭
  105. #PidFile /var/run/sshd.pid             --ssh的pid地方 可以获得ssh服务的进程id
  106. #MaxStartups 10:30:100
  107. #PermitTunnel no
  108. #ChrootDirectory none
  109. # no default banner path
  110. #Banner none
  111. # override default of no subsystems
  112. Subsystem sftp /usr/libexec/openssh/sftp-server
  113. # Example of overriding settings on a per-user basis
  114. #Match User anoncvs
  115. # X11Forwarding no
  116. # AllowTcpForwarding no
  117. # ForceCommand cvs server



来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27039319/viewspace-2104347/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-05-29

  • 博文量
    96
  • 访问量
    286804