linux远程服务管理openssh

82 篇文章 3 订阅

################ 1.openssh ################################

当主机中开启openssh服务,那么就对外开放了远程连接的接口

#openssh服务的服务端-------------- sshd

 #openssh服务的客户端-----------------ssh

 

 

############# 2.在客户端连接sshd的方式 ########################################

ssh   服务端用户@服务端ip地址



例如

ssh   root@172.25.0.10 ##在客户端用ssh命令连接172.25.0.10主机的root用户

 

[root@localhost ~]# ssh root@172.25.254.200

The authenticity of host '172.25.254.200 (172.25.254.200)' 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)? ##当当前主机第一次连接陌生主机时

##会自动建立.ssh/know_hosts

##这个文中记录的是连接过的主机信息

#

root@172.25.254.200's password: #进行此操作需要知道对方密码,输入密码连接成功

Last login: Fri Mar 30 02:05:52 2018 from 172.25.254.100

[root@localhost ~]# exit #表示退出当前连接

logout

Connection to 172.25.254.200 closed.

 "注意:以上连接方式是不能打开远程主机的图形功能的如果需要打开远程主机图形功能需要输入 -X"

(1)ssh -X root@172.25.254.1

(2)输入对方的密码passwd

 (3)cheese  ##开启摄像头


########### 3.给ssh服务添加新的认证方式 KEY认证###########################

 1.生成锁和钥匙

[root@localhost ~]# ssh-keygen ##生成密钥的命令

Generating public/private rsa key pair.

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

Created directory '/root/.ssh'.

Enter passphrase (empty for no passphrase): #可以为空,如果想为空必须大于4位

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:

00:4f:b0:72:40:9f:a6:fb:91:86:d2:69:bc:7c:75:5f root@localhost

The key's randomart image is:

+--[ RSA 2048]----+

| .o o..          |

|   o *           |

|  . * o          |

|   =   .         |

|  .     S        |

| o + .. .   E    |

|. B +. . . .     |

| + +..    .      |

|  o..            |

+-----------------+

 

2.加密ssh用户的认证

#在服务端

ssh-copy-id -i /root/.ssh/id_rsa.pub root@服务端Ip地址

ssh-copy-id ##加密命令

-i ##指定密钥

/root/.ssh/id_rsa.pub ##密钥

root ##加密用户

172.25.254.200 ##主机ip


 

3.验证

#解密文件传输到客户端

scp /root/.ssh/id_rsa  root@172.25.254.138:/root/.ssh/


 

#在客户端

ssh root@172.25.254.100 #连接不需要密码

 #在服务端

rm -fr /root/.ssh/authorized_keys ##当此文件被删除,客户端解密文件失效


 #在服务端

cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys ##重新生成锁文件,解密文件功能恢复

 

具体操作:

<1>ssh-keygen(在服务端上)

<2>一直按回车,直到出现密码图案

<3>ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.238

<4>ls -l /root/.ssh

<5>scp /root/.ssh/id_rsa root@172.25.254.138:/root/.ssh/

<6>打开另外一个虚拟机(在desktop上),登陆设置密码的虚拟机:ssh root@172.25.254.238,此时就是免密登陆

注:先查看desktop上是否有/root/.ssh/目录  ls -l /root/

   如果没有,就随意登陆一个虚拟机,此刻就已经创建了一个/root/.ssh/目录了

<7>在desktop上,删除 /root/.ssh/id_rsa

<8>再次登陆,需要密码

 

############ 4.sshd的安全配置 #########################################

服务端修改配置文件: vim  /etc/ssh/sshd_config

78 PasswordAuthentication no|yes ##开启或关闭ssh的默认认证方式

48 PermitRootLogin no|yes ##开启或关闭root用户的登陆权限

79 AllowUsers westos ##用户白名单,当前设定是只允许westos登陆

80 DenyUsers linux ##用户黑名单,当前设定是只不允许linux登陆

需要注意的是白名单和黑名单只能出现一个。


 

2、控制ssh客户端访问

vim /etc/hosts.deny

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

 

 

 

############## 5.linux中服务的管理 #############################################

systemctl    动作 服务

systemctl start sshd #开启服务

systemctl stop sshd #停止服务

systemctl status sshd #查看服务状态

systemctl restart sshd #重启服务

systemctl reload sshd #让服务从新加载配置

systemctl enable sshd #设定服务开启启动

systemctl disable sshd #设定服务开机不启动

 

systemctl list-unit-files #查看系统中所有服务的开机启动状态

systemctl list-units #查看系统中所有开启的服务

systemctl set-default graphical.target #开机时开启图形

systemctl set-default multi-user.targe #开机时不开图形

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值