且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ssh和sshd命令

更新时间:2022-10-04 22:02:06

1.openssh-server

功能:让远程主机可以通过网络访问sshd服务,开始一个安全shell

2.客户端连接方式

ssh远程主机用户@远程主机ip


[root@desktop0 ~]# ssh root@172.25.0.11功能:让远程主机可以通过网络访问sshd服务,开始一个安全shell

The authenticity of host '172.25.0.11 (172.25.0.11)' can't be established.

ECDSA key fingerprint is eb:24:0e:07:96:26:b1:04:c2:37:0c:78:2d:bc:b0:08.

Are you sure you want to continue connecting (yes/no)? yes##连接陌生主机时需要建立认证关系

Warning: Permanently added '172.25.0.11' (ECDSA) to the list of known hosts.

root@172.25.0.11's password: ##远程用户密码

Last login: Mon Oct  3 03:13:47 2016

[root@server0 ~]###登陆成功

ssh和sshd命令

ssh 远程主机用户@远程主机ip -X##调用远程主机图形工具  eg ssh root@172.25.254.51 -X   gedit file(打开出另外一个主机的file)

ssh     远程主机用户@远程主机ipcommand##直接在远程主机运行某条命令 eg ssh root@172.25.254.51 "touch file1" (就在ip为172.25.254.51的主机中有了一个file的文件)

当两台虚拟机同时开启的时候会,会明显感觉到卡顿,这个时候就可以在真机中进行如下操作

ssh和sshd命令

通过Memory改变占用内存大小

ssh和sshd命令

3.ssh登陆提示修改该

vim /etc/motd##显示登陆后字符

hello world##在登陆后就会显示这个字符

ssh和sshd命令

当客户端连接到服务器端的时候就会出现提示

ssh和sshd命令


####3.sshkey加密####

1.生成公钥私钥

[root@server0 ~]# ssh-keygen ##生成公钥私钥工具

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):[enter] ##加密字符保存文件(建议用默认)

Created directory '/root/.ssh'.

Enter passphrase (empty for no passphrase): [enter]##密钥密码,必须>4个字符

Enter same passphrase again: [enter]##确认密码

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:

ab:3c:73:2e:c8:0b:75:c8:39:3a:46:a2:22:34:84:81 root@server0.example.com

The key's randomart image is:
+--[ RSA 2048]----+
+--[ RSA 2048]----+

|o                |

|E.               |
|..               |
|.  . o           |
|.o. * . S        |
|oo.o o   .       |
|+ =. .  .        |
|o. oo.+..        |
|    ..o*.        |
+-----------------+

通过ssh-keygen生成钥匙和锁


ssh和sshd命令

id_rsa  私钥,就是钥匙

id_rsa.pub  公钥,就是锁

4.添加key认证方式

[root@server0 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub  root@172.25.0.11(这个ip为套被链接的ip,就是给自己加锁,并且将自己的openssh-server配置文件:/etc/ssh/sshd_config改passwordautentication=no)

ssh-copy-id  添加key认证方式的工具

-i  指定加密key文件

/root/.ssh/id_rsa.pub  加密key

root   加密用户为root

172.25.0.11  被加密主机ip

当再一次连接时候就会表示连接不到

ssh和sshd命令

4.分发钥匙给client主机

ssh和sshd命令

客户端显示收到钥匙,此时就可以不要密码来连接了。

ssh和sshd命令

6.提升openssh的安全级别

1.openssh-server配置文件  /etc/ssh/sshd_config

78 PasswordAuthentication yes|no##是否开启用户密码认证,yes为支持no为关闭

48 PermitRootLogin yes|no##是否允许超级用户登陆

49 AllowUsers student westos##用户白名单,只有在名单中出现的用户可以使用sshd建立shell

ssh和sshd命令

在 /etc/ssh/sshd_config中先把上边的passwordautentication=no改回到'yes'

在添加用户名

50 DenyUsers westos##用户黑名单

ssh和sshd命令

要注意百名单和黑名单不能把一个用户同时出现,否则就会有异常


2.控制ssh客户端访问

vim /etc/hosts.deny

sshd:ALL##拒绝所有人链接sshd服务

ssh和sshd命令

sshd:172.25.254.250, 172.25.254.55  允许250和180链接

ssh和sshd命令


















本文转自技术小白JDY51CTO博客,原文链接:http://blog.51cto.com/13355576/1973917 ,如需转载请自行联系原作者