ssh服务

Posted skyzy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ssh服务相关的知识,希望对你有一定的参考价值。

ssh服务: linux下远程管理工具 tcp 22号 openssl(加密工具) openssh-server 基于密钥对的加密方式: dsa 对称的公钥加密算法,安全性相对较低,数据传输速度相对较快;使用同一个密钥进行加密和解密 rsa 非对称加密算法(ssh默认算法),安全性较高,数据传输速度相对较慢;用公钥加密和私钥解密,... 从客户端来讲,两种认证方式: 1、基于口令密码的认证(密码) (1) server端通过非对称加密方式产生一个公钥 (2)client发起请求,server将公钥暴露给客户端 (3)client获取公钥后,会产生一个由256位随机数组成的一个会话密钥(临时,口令) (4)client端通过公钥将会话口令进行加密发送给server端 (5)server端拿者私钥进行解密,获取到会话密钥(口令) (6)client端和server端数据传输通过该口令进行对称加密 demo: # ssh serverip ——> 提示输入server端的root密码 redhat$ ssh serverip ——>提示输入server端的redhat密码 # ssh -lusername serverip ——>提示输入server端指定的用户密码 # ssh -p port serverip ——>指定端口号登录 -l: -p: 2、基于密钥对的认证(密钥认证) (1)client端需要产生一对密钥(公钥和私钥) (2)client端将自己的公钥远程传递到server端 (3)client ——>ssh server——>server server找到client端的公钥匹配验证,一致,询问加密 client拿着自己的私钥进行解密——>server确认登录 server:openssh-server # rpm -qa|grep ^openssh openssh-server-5.3p1-94.el6.x86_64 服务端 openssh-clients-5.3p1-94.el6.x86_64 客户端工具 openssh-5.3p1-94.el6.x86_64 工具包 openssh-askpass-5.3p1-94.el6.x86_64 基于gnome桌面的工具包 /etc/pam.d/ssh-keycat /etc/pam.d/sshd 认证文件 /etc/rc.d/init.d/sshd 启动脚本 /etc/ssh/sshd_config 主配置文件 /usr/sbin/sshd 二进制的命令 # rpm -ql openssh-clients /etc/ssh/ssh_config 客户端配置文件 /usr/bin/.ssh.hmac /usr/bin/scp /usr/bin/sftp /usr/bin/slogin /usr/bin/ssh /usr/bin/ssh-add /usr/bin/ssh-agent /usr/bin/ssh-copy-id /usr/bin/ssh-keyscan 了解配置文件: demo1:更改服name=rhel-6.5 baseurl=file:///media/RHEL_6.5 x86_64 Disc 1/ enabled=1 gpgcheck=0 务的端口为10022 # vim /etc/ssh/sshd_config .. port 10022 demo2:不允许root用户登录 # vim /etc/ssh/sshd_config .. PermitRootLogin no demo3:禁止使用空密码登录 PermitEmptyPasswords yes 代表允许空密码登录;no代表不允许 demo4:免密码登录 client:10.1.1.2 server:10.1.1.1 client: (1)生成一对密钥 # ssh-keygen (/usr/bin/ssh-keygen) 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: 0d:4f:84:3b:bb:b8:50:a2:03:49:fe:91:71:a0:73:ba [email protected] The key‘s randomart image is: +--[ RSA 2048]----+ | . .. | | . . .. | | + o . ... | |o.+ + o= | |oo o. . Soo | | .o..o . | | Eo.. . . | | . .. . | | .. | +-----------------+ 2)将公钥远程传递给server端 # ssh-copy-id -i id_rsa.pub 10.1.1.1 The authenticity of host ‘10.1.1.1 (10.1.1.1)‘ can‘t be established. RSA key fingerprint is eb:c0:3b:54:06:88:8b:ad:db:a0:a6:8c:74:56:b3:52. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added ‘10.1.1.1‘ (RSA) to the list of known hosts. [email protected]‘s password: Now try logging into the machine, with "ssh ‘10.1.1.1‘", and check in: .ssh/authorized_keys to make sure we haven‘t added extra keys that you weren‘t expecting. 或者 # scp -P10022 id_rsa.pub 10.1.1.1:/root/.ssh/authorized_keys [email protected]‘s password: 3>测试验证 # ssh 10.1.1.1(不需要输入密码直接登录) 作业3: 将ssh服务托管给xinetd服务管理 要求: 1、只允许10.1.1.0/24和172.16.250.2使用ssh远程登录 2、不允许10.1.1.2访问 3、控制该服务最多只能3个连接,每个源ip只能1个连接 4、控制只能在9:00-18:00才能远程登录 5、指定日志到/var/log/xinetd_ssh.log里 6、更改ssh服务的默认端口为10000 # service sshd stop # vim /etc/xinetd.d/ssh service ssh { flags = REUSE socket_type = stream wait = no user = root server = /usr/sbin/sshd log_on_failure += USERID disable = no server_args = -i only_from = 10.1.1.0/24 172.16.250.2 no_access = 10.1.1.2 instances = 3 per_source = 1 access_times = 09:00-18:00 log_type = file /var/log/xinet_ssh.log port = 10000 } # netstat -nltp|grep 22 tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 2214vsftpd tcp 0 0 :::22 :::* LISTEN 9125/xinetd client端:ssh 10.1.1.110

以上是关于ssh服务的主要内容,如果未能解决你的问题,请参考以下文章

ssh服务

关闭ssh后,服务依旧运行

ubuntu如何开启ssh服务

SSH服务审计工具ssh-audit

如何开启ubuntu的SSH服务

ssh怎么连接服务器