远程访问及控制

文章目录

  • 远程访问及控制
  • 一、ssh基本配置
    • 1. 允许root登录
    • 2. 禁止root远程登录
    • **注意
    • 3. DenyUsers 黑名单的使用
    • 4. AllowUsers 白名单使用
    • 5. 设置输错密码次数
  • 二、sshd密钥对登录
    • 步骤一:服务器192.168.75.134 配置
    • 步骤二: 被连接的服务器 192.168.75.134
    • 步骤三:客户端服务器配置
  • 三、ssh客户端 (scp 、sftp)
    • 3.1 不同终端登录情况
    • 3.2 scp 远程复制文件和目录
      • 客户端配置
      • ssh服务端查看复制的ssh_client 文件
    • 3.3 sftp远程文件传输
  • 四、TCP Wrappers

一、ssh基本配置


[root@localhost ttyy]# cd /etc/ssh/
[root@localhost ssh]# ll
总用量 604
-rw-r--r--. 1 root root     581843 4月  11 2018 moduli
-rw-r--r--. 1 root root       2276 4月  11 2018 ssh_config
-rw-------. 1 root root       3907 4月  11 2018 sshd_config
-rw-r-----. 1 root ssh_keys    227 6月  20 00:15 ssh_host_ecdsa_key
-rw-r--r--. 1 root root        162 6月  20 00:15 ssh_host_ecdsa_key.pub
-rw-r-----. 1 root ssh_keys    387 6月  20 00:15 ssh_host_ed25519_key
-rw-r--r--. 1 root root         82 6月  20 00:15 ssh_host_ed25519_key.pub
-rw-r-----. 1 root ssh_keys   1679 6月  20 00:15 ssh_host_rsa_key
-rw-r--r--. 1 root root        382 6月  20 00:15 ssh_host_rsa_key.pub
[root@localhost ssh]# vi sshd_config
[root@localhost ssh]# systemctl restart sshd

1. 允许root登录

[root@localhost ~]# ssh tom1@192.168.75.134   //切换到192.168.75.134服务器tom1用户
The authenticity of host '192.168.75.134 (192.168.75.134)' can't be established.
ECDSA key fingerprint is SHA256:bU1FwZbMBoEUpA1iqsRfqnbPi177StbfmKB0vk38WTM.
ECDSA key fingerprint is MD5:2c:bd:95:89:e2:b7:dc:db:43:a8:dc:60:e0:2c:bb:74.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added '192.168.75.134' (ECDSA) to the list of known hosts.
tom1@192.168.75.134's password:
Last login: Sun Jul  5 22:22:02 2020
[tom1@localhost data]$ ll
总用量 0
-rwxr-x--x. 1 ttyy root 0 6月  29 19:20 3.txt
[tom1@localhost data]$ df -Th      //成功切换到192.168.74.134服务器的Tom1用户
文件系统       类型      容量  已用  可用 已用% 挂载点
/dev/sda3      xfs       182G  5.3G  177G    3% /
devtmpfs       devtmpfs  2.0G     0  2.0G    0% /dev
tmpfs          tmpfs     2.0G     0  2.0G    0% /dev/shm
tmpfs          tmpfs     2.0G   11M  2.0G    1% /run
tmpfs          tmpfs     2.0G     0  2.0G    0% /sys/fs/cgroup
/dev/sda1      xfs      1014M  174M  841M   18% /boot
tmpfs          tmpfs     406M  8.0K  406M    1% /run/user/42
tmpfs          tmpfs     406M   32K  406M    1% /run/user/1000
tmpfs          tmpfs     406M     0  406M    0% /run/user/1505
[tom1@localhost data]$ su   //Tom1用户成功切换到root用户
密码:
[root@localhost data]#
[root@localhost data]# touch 111.txt
[root@localhost data]# ll
总用量 0
-rw-r--r--. 1 root root 0 7月   8 19:04 111.txt
-rwxr-x--x. 1 ttyy root 0 6月  29 19:20 3.txt
[root@localhost data]#
[root@localhost data]# exit       //退出当前终端
exit
[tom1@localhost data]$ exit    //退出当前终端用户
登出
Connection to 192.168.75.134 closed   

2. 禁止root远程登录

vi /etc/sshd.conf

[root@localhost ~]# ssh root@192.168.75.134
root@192.168.75.134's password: Permission denied, please try again.           //验证root账号无法登录
root@192.168.75.134's password:
Permission denied, please try again.
root@192.168.75.134's password: 

**注意

一般在sshd.conf配置文件中禁止PermitRootLogin no 并不能绝对的禁止root登录,也有一些wheel组的用户,可以切换到root账号,所以这个方法并不是完全安全性。**

vi /etc/pam.d/su

[root@localhost pam.d]# gpasswd -a tom1 wheel

正在将用户“tom1”加入到“wheel”组中

开启这个功能之后,只有指定的用户在wheel组中才能切换root账号。

3. DenyUsers 黑名单的使用

[root@localhost ~]# vi /etc/ssh/sshd_config
[root@localhost ~]# systemctl reload sshd

使用服务器192.168.75.137验证如下


4. AllowUsers 白名单使用

AllowUsers tom1 ttyy@192.168.75.137 //白名单只允许tom1在所有终端远程连接,ttyy用户只能在192.168.75.137的终端远程连接过来

验证192.168.75.137使用ttyy用户成功登陆192.168.75.134

验证192.168.75.129使用ttyy用户无法登陆192.168.75.134

5. 设置输错密码次数

MaxAuthTries 6 //是指登录连接的次数,不是输错密码的次数。默认输错密码的次数是3次

添加输错密码的错误: 在连接方服务器输入:
ssh -o NumberOfPasswordPrompts=8 tom1@192.168.75.134
注:这里添加的是允许输错密码的次数。
192.168.75.134是被连接的服务器ip地址,zhangsan用户也是被连接的用户

MaxAuthTries 6 是输入次数但是默认是输错密码次数是3。
所以一般改这个参数只是连接次数不是输错密码的次数。

二、sshd密钥对登录

实验:使用加密 ecdsa 算法进行加密验证登录
加密登录过程
第一步:
第二步:
第三步:
第四步:

vi /etc/sshd/sshd_conf

AuthorizedKeysFile .ssh/authorized_keys //存放密钥文件

步骤一:服务器192.168.75.134 配置

[caiwu@localhost root]$ ssh-keygen -t ecdsa   //客户机生产密钥文件放到家目录下  密码设置为6个
Generating public/private ecdsa key pair.
Enter file in which to save the key (/home/caiwu/.ssh/id_ecdsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/caiwu/.ssh/id_ecdsa.
Your public key has been saved in /home/caiwu/.ssh/id_ecdsa.pub.
The key fingerprint is:
SHA256:T/yHHv3X6AhOEQ8pLtw/LmFHWkn2/X34kDNhsZPI6D8 caiwu@localhost.localdomain
The key's randomart image is:
+---[ECDSA 256]---+
|                 |
|          o.  .  |
|        .o+= o + |
|     . o o=++ B  |
|      o S=+ .. *.|
|       .++oo o* +|
|       . o*.+ o*o|
|        .+ +E+..+|
|         .o oo. o|
+----[SHA256]-----+
[caiwu@localhost root]$ [caiwu@localhost root]$ cd /home/
[caiwu@localhost home]$ ll
总用量 4
drwx------.  6 caiwu caiwu  119 7月   9 11:07 caiwu
drwx------. 15 ttyy  ttyy  4096 7月   9 10:04 ttyy
[caiwu@localhost home]$ ls -a
.  ..  caiwu  ttyy
[caiwu@localhost home]$ ll
总用量 4
drwx------.  6 caiwu caiwu  119 7月   9 11:07 caiwu
drwx------. 15 ttyy  ttyy  4096 7月   9 10:04 ttyy
[caiwu@localhost home]$ cd caiwu/
[caiwu@localhost ~]$ ll
总用量 0
[caiwu@localhost ~]$ ls -a
.   .bash_logout   .bashrc  .config   .ssh
..  .bash_profile  .cache   .mozilla
[caiwu@localhost ~]$
[caiwu@localhost ~]$ cd .ssh/
[caiwu@localhost .ssh]$ ll
总用量 8
-rw-------. 1 caiwu caiwu 314 7月   9 11:08 id_ecdsa
-rw-r--r--. 1 caiwu caiwu 189 7月   9 11:08 id_ecdsa.pub
[caiwu@localhost .ssh]$ ssh-copy-id -i id_ecdsa.pub tom2@192.168.75.134    //将客户机的密钥复制到连接端中
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "id_ecdsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
tom2@192.168.75.134's password:          //输入tom2的登录密码不是caiwu 用户的登录密码Number of key(s) added: 1Now try logging into the machine, with:   "ssh 'tom2@192.168.75.134'"
and check to make sure that only the key(s) you wanted were added.
[caiwu@localhost .ssh]$ ll
总用量 12
-rw-------. 1 caiwu caiwu 314 7月   9 11:08 id_ecdsa
-rw-r--r--. 1 caiwu caiwu 189 7月   9 11:08 id_ecdsa.pub
-rw-r--r--. 1 caiwu caiwu 176 7月   9 11:14 known_hosts   //本机私钥
[caiwu@localhost .ssh]$ vi known_hosts      

步骤二: 被连接的服务器 192.168.75.134

[root@localhost home]# cd /home/tom2      //查看家目录的文件
[root@localhost tom2]# ll
总用量 0
[root@localhost tom2]# ls -a
.  ..  .bash_history  .bash_logout  .bash_profile  .bashrc  .cache  .config  .mozilla  .ssh    //192.168.75.137服务器caiwu用户复制过来的公钥数据
[root@localhost tom2]# cd .ssh/
[root@localhost .ssh]# ll -s
总用量 4
4 -rw-------. 1 tom2 tom2 189 7月   9 11:16 authorized_keys //192.168.75.137服务器caiwu用户复制过来的公钥数据
[root@localhost .ssh]#
[root@localhost .ssh]# cat authorized_keys
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNuyyIZsMeV2/GUqH2w75D/RF77pp0DnX4QU5xZFOMW7rvfVs+J1wHv3Rps57bIzqQUQxl7SP0f+3C5nUPHixFs= caiwu@localhost.localdomain    192.168.75.137服务器caiwu用户复制过来的公钥数据

步骤三:客户端服务器配置


[caiwu@localhost .ssh]$ whoami
caiwu
[caiwu@localhost .ssh]$ ssh tom2@192.168.75.134
Enter passphrase for key '/home/caiwu/.ssh/id_ecdsa':            //这边输入的密码是设置的ecdsa的加密 密码
Last login: Wed Jul  1 14:59:01 2020
[tom2@localhost ~]$       //成功登录tom2用户
设置
[tom2@localhost ~]$ exit
登出
Connection to 192.168.75.134 closed.
设置ecdsa加密算法的免登陆,首先要退到caiwu用户状态
[caiwu@localhost .ssh]$ ssh-agent bash
[caiwu@localhost .ssh]$ ssh-add
Enter passphrase for /home/caiwu/.ssh/id_ecdsa:       //输入ecdsa 密码
Identity added: /home/caiwu/.ssh/id_ecdsa (/home/caiwu/.ssh/id_ecdsa)
[caiwu@localhost .ssh]$
[caiwu@localhost .ssh]$ ssh tom2@192.168.75.134      //验证免密码登录,这个方法不适合公共电脑,没有安全性
Last login: Thu Jul  9 11:29:03 2020 from 192.168.75.137
[tom2@localhost ~]$

三、ssh客户端 (scp 、sftp)

3.1 不同终端登录情况

如果sshd的配置文件中 /ssh/sshd_conf 中的port 22改为123终端号,那么远程连接的时候需要输入

ssh -p 123 tom2@192.168.75.134

3.2 scp 远程复制文件和目录

注:提前将ssh服务器端的权限放空。允许root账号登录

客户端配置

[root@localhost opt]# cd data/
[root@localhost data]# echo "this is ssh_client" > ssh_client  //新建文件
[root@localhost data]# ll
总用量 4
-rw-r--r--. 1 root root 19 7月   9 11:55 ssh_client
[root@localhost data]# mkdir test  //新建目录
[root@localhost data]# ll
总用量 4
-rw-r--r--. 1 root root 19 7月   9 11:55 ssh_client
drwxr-xr-x. 2 root root  6 7月   9 11:55 test
[root@localhost data]# scp ssh_client root@192.168.75.134:/home/    //客户端远程复制文件 ssh_client 文件的ssh服务器家目录中
root@192.168.75.134's password:    //输入root密码
ssh_client                                                                                                                               100%   19    10.2KB/s   00:00
[root@localhost data]#
[root@localhost data]# scp -r test/ root@192.168.75.134:/home/     //客户端远程递归复制目录 test的ssh服务器家目录中
root@192.168.75.134's password:
[root@localhost data]# 

ssh服务端查看复制的ssh_client 文件

[root@localhost data]# cd /home/
[root@localhost home]# ll
总用量 8
drwx------.  3 kgc  kgc    78 6月  24 11:11 kgc
drwx------.  3 lisi lisi   78 6月  24 11:18 lisi
-rw-r--r--.  1 root root   19 7月   9 11:58 ssh_client    //客户端成功远程复制成功
drwx------.  6 tom2 tom2  140 7月   9 11:16 tom2
drwxr-xr-x.  2 root root    6 7月   9 12:04 test      //客户端成功远程复制成功
drwx------. 15 ttyy ttyy 4096 7月   9 10:04 ttyy
[root@localhost home]# 

3.3 sftp远程文件传输

下载服务端文件到本地

[root@localhost data]# sftp root@192.168.75.134     //远程登录ssh服务端
root@192.168.75.134's password:
Connected to 192.168.75.134.
sftp> cd /opt
sftp> touch 1.txt   //在服务器端opt目录下新建一个1.txt文件
sftp> cd /
sftp> get 1.txt /opt/data/   //将服务端的1.TXT文件下载到客户端/opt/data目录下
Fetching /1.txt to /opt/data/1.txt
/1.txt                                    100%    4     1.5KB/s   00:00
sftp> bye  //退出服务端
[root@localhost data]# ll
总用量 8
-rw-r--r--. 1 root root  4 7月   9 12:12 1.txt    //成功下载到客户端
-rw-r--r--. 1 root root 19 7月   9 12:10 ssh_client
drwxr-xr-x. 2 root root  6 7月   9 11:55 test

上传本地文件到服务端

[root@localhost opt]# cd data/
[root@localhost data]# ll
总用量 8
-rw-r--r--. 1 root root  4 7月   9 12:12 1.txt
-rwxrwxrwx. 1 root root  0 7月   9 12:18 777.txt
-rw-r--r--. 1 root root 19 7月   9 12:10 ssh_client
drwxr-xr-x. 2 root root  6 7月   9 11:55 test
[root@localhost data]# sftp root@192.168.75.134
root@192.168.75.134's password:
Connected to 192.168.75.134.
sftp> put 777.txt
Uploading 777.txt to /root/777.txt   //本地的文件上传到服务器root家目录中
777.txt                                   100%    0     0.0KB/s   00:00
sftp> 

服务端

[root@localhost /]# cd ~
[root@localhost ~]# ll
总用量 12
-rw-r--r--. 1 root root    0 7月   9 12:32 777.txt  //服务端上传文件成功
-rw-------. 1 root root 1762 6月  20 00:13 anaconda-ks.cfg
-rw-r--r--. 1 root root 1810 6月  20 00:15 initial-setup-ks.cfg
----------. 1 root root 1526 6月  22 19:53 shadow.txt
-rw-r--r--. 1 root root    0 7月   9 12:25 to
drwxr-xr-x. 2 root root    6 6月  20 00:15 公共
drwxr-xr-x. 2 root root    6 6月  20 00:15 模板
drwxr-xr-x. 2 root root    6 6月  20 00:15 视频
drwxr-xr-x. 2 root root    6 6月  20 00:15 图片
drwxr-xr-x. 2 root root    6 6月  20 00:15 文档
drwxr-xr-x. 2 root root    6 6月  20 00:15 下载
drwxr-xr-x. 2 root root    6 6月  20 00:15 音乐
drwxr-xr-x. 2 root root    6 6月  20 00:15 桌面
[root@localhost ~]# 

四、TCP Wrappers

centos 7.6 ——远程访问及控制——(ssh密钥登录、ssh客户端、TCP Wrappers)相关推荐

  1. CentOS设置ssh密钥登录

    2019独角兽企业重金招聘Python工程师标准>>> CentOS设置ssh密钥登录 centos 系统安全防御 2017年12月2日 329 0 0 一.生成密钥对(两种方式)并 ...

  2. 腾讯云服务器使用ssh密钥登录--个人常遇到问题均解决

    什么是SSH密钥对 SSH密钥是一种无须密码登录Linux实例的认证方式. 通过加密方法生成一对SSH密钥,一个对外公开密钥,成为公钥,一个由您保密保存,称为私钥. 将公钥存放于您的Linux实例中, ...

  3. vscode 使用ssh密钥登录远程Linux -- vscode remote linux ssh key

    此文首发于我的个人博客:vscode 使用ssh密钥登录远程 Linux – vscode remote linux ssh key - zhang0peter的个人博客 推荐先看文章:Windows ...

  4. ssh密钥登录 改密码登录_如何使用密钥对通过SSH登录而不使用密码

    ssh密钥登录 改密码登录 In last post we saw how to use Expect Script for login to remote server using SSH. The ...

  5. 如何使用SSH密钥登录你的云服务器?使用SSH密钥的好处

    什么是SSH秘钥对? ssh秘钥对是通过一种加密算法生产的一对秘钥: 一个对外界公开,称为"公钥": 另一个我们自己保留,称为"私钥". 公有和私有密钥被称为密 ...

  6. 使用SSH密钥登录腾讯云主机

    需求:使用SSH密钥登录腾讯云主机以获得更好的安全性. 登录腾讯云控制台,点击"创建密钥": 创建一个新的密钥,维护一个名称: 密钥创建之后,绑定到一台可用的腾讯云主机实例. 先把 ...

  7. 用安卓手机远程管理linux,支持SSH密钥登录

    今天在安卓手机市场发现一个神奇的软件,可以远程linux服务器并且支持SSH密钥登录. 大家可以在安卓市场搜索connetbot,名字为lrssi ConnectBot的就是.上面虽然写的是英文版的, ...

  8. xshell使用SSH密钥登录Linux实例

    在本地Windows系统中打开xshell. 工具栏上打开 工具 > 新建用户密钥生成向导 在新建会话属性的 连接 配置中输入会话名称和您的云服务器IP地址 点击 连接 中的用户身份验证,方法选 ...

  9. 使用密钥登录SSH服务器

    原理: SSH登录除了传统的密码登录,可以使用密钥文件登录,结合PAM模块,也可以实现双因子登录 服务器ip: 192.168.31.133 一.配置服务器SSH密钥登录 以下操作使用服务器进行 1. ...

最新文章

  1. 重磅日程公布!与百名大咖在线交流技术,2天20个AI论坛不可错过
  2. Datawhale自组织学习报告!
  3. Elastic Search入门:架构说明及Docker方式体验
  4. 源码学习【原子类AtomicInteger】Java原子类底层实现(解释详细)
  5. 一加7充电_刘作虎:一加7没有无线充电,Dash是最好的快充之一
  6. [WPF疑难]如何禁用WPF窗口的系统菜单(SystemMenu)
  7. event mpm php,Ubuntu Apache 切换到php-fpm+mpm_event模式
  8. SpringMVC全局异常处理机制常见问题及底层实现分析
  9. 夜间灯光数据dn值_探讨DMSPOLS夜间灯光数据的校正
  10. java如何删除文件夹_Java如何删除文件夹和子文件夹
  11. Java Web项目开发项目经验总结
  12. 曲线运动与万有引力公式_物质自旋与力的形成 ——关于万有引力与磁荷力本质与统一问题的探讨...
  13. 工厂模式(Factory Method)
  14. java导出mysql数据表的结构生成word文档
  15. 复活Google右键翻译方法及Google浏览器网页一键翻译
  16. 免费建立个人网站怎么做?教你简单的方法
  17. Python学习 之 tenacity重试模块
  18. 实现了私聊和群聊功能的聊天工具
  19. 百度2016研发工程师在线编程题
  20. GOOGLE搜索秘籍--高级搜索:site,link,inurl,allinurl,intitle,allintitle

热门文章

  1. “核高基”的专家有哪些人?
  2. homeassistant
  3. homeassistant搭建_梅林搭建home-assistant
  4. 网康防火墙--上线指南_在线付款接受指南-第2部分
  5. 浅谈TCP半连接攻击与全连接攻击
  6. Windows安装TensorFlow教程(国内源安装附上各大镜像网站网址)
  7. 超级计算机的等级,亿亿次级别运算曙光初现-超级计算机,千万亿次,TeraScale,万万亿次,ExaScale ——快科技(驱动之家旗下媒体)--科技改变未来...
  8. 线光谱共焦如何检测3D曲面玻璃
  9. android二维码
  10. 2019长安大学ACM校赛网络同步赛 Trial of Devil