环境

(1)Kali(源主机),IP:10.211.55.4/24

(2)Ubuntu(目标主机),IP:10.211.55.5/24

SSH

OpenSSH用于在远程系统上安全的运行Shell,假设现在需要在Kali机器上通过root用户远程登陆另一台机器Ubuntu,那么就可以使用SSH服务,但是使用SSH登录每次都需要输入密码,为了节省时间,可以配置SSH免密登陆。这样Kali这台机器就可以通过SSH直接登陆到Ubuntu

SSH免密登陆

主机连通性

首先使用ping命令确保两台主机的连通性。

┌──(root㉿kali-linux-2022-2)-[~]
└─# ping 10.211.55.5
PING 10.211.55.5 (10.211.55.5) 56(84) bytes of data.
64 bytes from 10.211.55.5: icmp_seq=1 ttl=64 time=0.928 ms
64 bytes from 10.211.55.5: icmp_seq=2 ttl=64 time=0.818 ms
64 bytes from 10.211.55.5: icmp_seq=3 ttl=64 time=0.832 ms
^C
--- 10.211.55.5 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2050ms
rtt min/avg/max/mdev = 0.818/0.859/0.928/0.048 ms

创建配置文件

Kali虚拟机虚拟机下创建SSH配置文件~/.ssh/config,先使用mkdir .ssh创建.ssh文件夹,然后进入.ssh文件夹通过touch config命令创建config文件,并在文件中配置以下按照格式配置以下信息:

Host 目标主机的别名
HostName 目标主机的IP或者域名
User 登陆目标主机使用的用户名

Kali上配置如下:

┌──(root㉿kali-linux-2022-2)-[~]
└─# cat ~/.ssh/config
Host ubuntu
HostName 10.211.55.5
User parallels

创建密钥

使用ssh-keygen命令创建密钥,所有的配置默认即可。

┌──(root㉿kali-linux-2022-2)-[~]
└─# 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:
SHA256:b/TY2e8TfhNTQu+lx+cnstlRZAeKEICVgKyGc2DeWy8 root@kali-linux-2022-2
The key's randomart image is:
+---[RSA 3072]----+
| . ..+ooo. . |
|..o . . . . ... |
|+o. . .. .+|
|+o.. . .o=|
|.o o . S . =+|
| . E . o + o.==|
| . + + +o=|
| . .o.*+|
| oo.oB|
+----[SHA256]-----+

创建完成之后,可以在.ssh文件下看到多出了两个文件:id_rsaid_rsa.pubid_rsa是私钥,

id_rsa.pub是公钥。

┌──(root㉿kali-linux-2022-2)-[~]
└─# ls .ssh
config id_rsa id_rsa.pub

发送公钥

现在只要将公钥传给你需要登录的主机即可,在这里就是将公钥传给ubuntu虚拟机,可以直接使用ssh-copy-id ubuntu将密钥传过去,这里的ubuntu就是之前在config文件里设置的别名。这里只需要输入一次parallels用户登陆ubuntu时使用的密码,也就是在config文件里设置的用户名对应的密码。

┌──(root㉿kali-linux-2022-2)-[~/.ssh]
└─# ssh-copy-id ubuntu
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '10.211.55.5 (10.211.55.5)' can't be established.
ED25519 key fingerprint is SHA256:lN78YGD118UAp/ZmzrtWnrqicHaFkJbs5pIZfTH06b0.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/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
parallels@10.211.55.5's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'ubuntu'"
and check to make sure that only the key(s) you wanted were added.

第一次与陌生的主机建立连接之后会自动创建.ssh/know_hosts文件,这个文件中记录的是连接过的主机的信息

登录测试

完成上述步骤之后,通过ssh 主机别名的方式就可以实现免密登陆,退出时直接使用exit就可以退出。

┌──(root㉿kali-linux-2022-2)-[~/.ssh]
└─# ssh ubuntu
Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.15.0-41-generic aarch64) * Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage This system has been minimized by removing packages and content that are
not required on a system that users do not log into. To restore this content, you can run the 'unminimize' command. 129 updates can be applied immediately.
32 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable Last login: Mon Aug 29 22:20:01 2022 from 10.211.55.4
parallels@ubuntu:~$
parallels@ubuntu:~$ exit
logout
Connection to 10.211.55.5 closed.

ssh和sshd

sshOpenSSH的服务端,sshdOpenSSH的客户端。

配置文件

有关SSH的配置文件在/etc/ssh目录下

┌──(root㉿kali-linux-2022-2)-[~/.ssh]
└─# cd /etc/ssh ┌──(root㉿kali-linux-2022-2)-[/etc/ssh]
└─# ls
moduli sshd_config.d ssh_host_ed25519_key.pub
ssh_config ssh_host_ecdsa_key ssh_host_rsa_key
ssh_config.d ssh_host_ecdsa_key.pub ssh_host_rsa_key.pub
sshd_config ssh_host_ed25519_key

其中,ssh_config的配置是针对ssh的,sshd_config的配置是针对sshd的,这两个文件根据当前机器是用作客户端还是服务端对应修改的,配置文件中的具体内容在后面用到时再详解解释。

root用户远程登录

root用户默认是不允许远程登录的,如果想要开启root用户远程登录,需要在ubuntu上找到/etc/ssh中的配置文件sshd_config,然后将这个文件的权限改为读写:

parallels@ubuntu:~$ cd /etc/ssh/
parallels@ubuntu:/etc/ssh$ sudo chmod 666 sshd_config

接着在这个文件末尾添加PermitRootLogin yes,最后使用service ssh restart命令重启SSH服务。

这时,在Kali上,将~/.ssh/config中的User改为root

Host ubuntu
HostName 10.211.55.5
User root

通过ssh-copy-id ubuntu将密钥传过去:

┌──(root㉿kali-linux-2022-2)-[~]
└─# ssh-copy-id ubuntu
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.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
root@10.211.55.5's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'ubuntu'"
and check to make sure that only the key(s) you wanted were added.

这样就可以实现root用户的免密登录:

┌──(root㉿kali-linux-2022-2)-[~]
└─# ssh ubuntu
Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.15.0-41-generic aarch64) * Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage This system has been minimized by removing packages and content that are
not required on a system that users do not log into. To restore this content, you can run the 'unminimize' command. 129 updates can be applied immediately.
32 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable root@ubuntu:~# who am i
root pts/1 2022-08-29 23:02 (10.211.55.4)
root@ubuntu:~# exit
logout
Connection to 10.211.55.5 closed.

Linux快速入门(八)效率工具(SSH)的更多相关文章

  1. Linux快速入门打开你的学习之道

    Linux快速入门打开你的学习之道 相信看到这篇文章的你一定是想要学习Linux,或者已经在学习Linux的人了,那我们就可以一起探讨一下,学习Linux如何快速入门呢? 首先,希望大家弄清楚自己为什 ...

  2. Linux快速入门教程-进程管理ipcs命令学习

    使用Linux系统必备的技能之一就是Linux进程管理,系统运行的过程正是无数进程在运行的过程.这些进程的运行需要占用系统的内存等资源,做好系统进程的管理,对于我们合理分配.使用系统资源有非常大的意义 ...

  3. Linux快速入门04-扩展知识

    这部分是快速学习的最后一部分知识,其中最重要的内容就是源码的打包和软件的安装的学习,由于个人的Linux学习目的就是自己能在阿里云Ubuntu上搭建一个简单的nodejs发布环境. Linux系列文章 ...

  4. Linux快速入门02-文件系统管理

    继续进入Linux文件系统的学习,加油,早日突破MS压在自己身上的那道束缚. Linux系列文章 快速入门系列--Linux--01基础概念 快速入门系列--Linux--02文件系统管理 快速入门系 ...

  5. Linux快速入门03-系统管理

    这部分将涉及常用的各类linux命令和一些系统高级管理特性,尤其是shell script的创建,这部分在系统自动化运维时会很有作用. Linux系列文章 快速入门系列--Linux--01基础概念 ...

  6. Linux快速入门01-基础概念

    4年多前,刚到上海时报过一个关于Oracle的培训班,在那里接触到了Linux,不过一直都没真正去试着使用它.现在经过慢慢的成长,越来越觉得,Linux是每一个服务端工程师必须掌握的系统,即使是现在最 ...

  7. NOI Linux 快速入门指南

    目录 关于安装 NOI Linux 系统配置 网络 输入法 编辑器 1. gedit 打开 配置 外观展示 2. vim 打开 配置 使用 makefile 编译运行 1. 编写 makefile 2 ...

  8. linux快速入门 1.1命令行操作

    http://lovesoo.org/linux-command-line-operation.html 1.1命令行操作 目录: <wp_nokeywordlink>Shell简介 &l ...

  9. Solr.NET快速入门(八)【多核多实例,映射验证】

    多核/多实例 本页介绍如何配置SolrNet访问(读/写)多个Solr内核或实例. 它假定您知道Solr内核是什么,如何在SolrNet外部配置和使用它们. 此页面不涵盖CoreAdminHandle ...

  10. Linux快速入门

    一.Linux介绍 1.Linux是基于Unix的开源免费的操作系统 2.Linux的分类: (1)Linux根据市场需求不同,基本分为两个方向: 1)图形化界面版:注重用户体验,类似window操作 ...

随机推荐

  1. .NET Core开发实战(第24课:文件提供程序:让你可以将文件放在任何地方)--学习笔记

    24 | 文件提供程序:让你可以将文件放在任何地方 文件提供程序核心类型: 1.IFileProvider 2.IFileInfo 3.IDirectoryContents IFileProvider ...

  2. C++——异常处理模块笔记

    异常处理是C++中的重要概念之一,用于处理在程序执行过程中可能发生的错误或异常情况.异常是指在程序执行过程中发生的一些不寻常的事件,例如除零错误.访问无效内存等.C++提供了一套异常处理机制,使得程序 ...

  3. JS leetcode x 的平方根 题解分析

    壹 ❀ 引 这几天心情复杂,也不知道形容.做道题吧,其实是上周的题,一直没整理,比较巧的是,这也是我同学17年去PPTV面试时遇到的一题,题目来自leetcode69. x 的平方根,题目描述如下: ...

  4. GCC Arm 11.3rel1, 12.2编译提示 _close is not implemented and will always fail

    使用GCC Arm工具链开发的项目, 在11.2下编译正常, 但是升级到 arm-gnu-toolchain-11.3.rel1 以及 arm-gnu-toolchain-12.2 之后, 编译出现警 ...

  5. 竞态问题与RxJs

    竞态问题与RxJs 竞态问题通常指的是在多线程的编程中,输入了相同的条件,但是会输出不确定的结果的情况.虽然Js是单线程语言,但由于引入了异步编程,所以也会存在竞态的问题,而使用RxJs通常就可以解决 ...

  6. SpringCloud Alibaba Sentinel实现熔断与限流<2020-9>

    SpringCloud Alibaba Sentinel 1.Sentinel是什么? 1.1.前言说明: 作用:实现熔断与限流 (Hystrix断路器 升级版) 文档直达: 官网中文文档 1.2.S ...

  7. 导致Redis访问慢的常见操作

    导致Redis访问慢的原因通常有2个方面: 第一,Redis本身性能出现了瓶颈,如:内存使用率过高,并发过大等 第二,存在大KEY,或者客户端访问命令使用不当引起的阻塞 在此,只列举因为的客户端命令使 ...

  8. 格式化占位符%r和!r

    # 作用 都是格式化原形输出,!r用于format格式化,%r用于%格式化 # 示例 a = '123' b = 'hello, {!r}'.format(a) b = 'hello, %r' % ( ...

  9. java+文件实现的超市管理系统

    一.需求 1.使用java语言实现系统 2.数据存储使用io读写文件 3.超市的商品管理+销售功能 二.效果 商品列表 商品增删改查 购买 三.说明 1.开发工具/技术 java  eclipse 2 ...

  10. C C++结构体四种方式

    第一种语法表示 struct 结构体名称 {     数据类型 member1:     数据类型 member2;  };  #include<iostream> using names ...