CentOS7配置SSH服务

1. SSH配置

1.1. 使用SSH服务更加安全

[root@centos7 ~]# vi /etc/ssh/sshd_config

设置如下

PermitRootLogin no

PermitEmptyPasswords no

PasswordAuthentication yes

[root@centos7 ~]# systemctl restart sshd

1.2. 设置防火墙,允许SSH服务使用22/TCP

[root@centos7 ~]# firewall-cmd --add-service=ssh –permanent

[root@centos7 ~]# firewall-cmd –reload

2. SSH文件传输

2.1. 应用SCP进行文件远程复制

2.1.1. 将本地文件复制到远程服务器

[root@centos7 ~]$ scp ./test.txt root@192.168.1.102:~/

root@192.168.1.102's password:

test.txt 100% 10 0.0KB/s 00:00

2.1.2. 将远程服务器文件复制到本地

[root@centos7 ~]$ scp root@192.168.1.102:/root/test.txt ./test.txt

root@192.168.1.102's password:

test.txt 100% 10 0.0KB/s 00:00

2.2. 应用SFTP进行文件远程复制

[root@centos7 ~]$ sftp root@192.168.1.102

root@192.168.1.102's password:

Connected to 192.168.1.102.

sftp>

# show current directory on remote server

sftp> pwd

Remote working directory: /root

# show current directory on local server

sftp> !pwd

/root

# show files in current directory on FTP server

sftp> ls -l

drwxrwxr-x 2 root root 6 Jul 29 21:33 public_html

-rw-rw-r-- 1 root root 10 Jul 28 22:53 test.txt

# show files in current directory on local server

sftp> !ls -l

total 4

-rw-rw-r-- 1 redhat redhat 10 Jul 29 21:31 test.txt

# change directory

sftp> cd public_html

sftp> pwd

Remote working directory: /root/public_html

# upload a file to remote server

sftp> put test.txt redhat.txt

Uploading test.txt to /root/redhat.txt

test.txt 100% 10 0.0KB/s 00:00

sftp> ls -l

drwxrwxr-x 2 root root 6 Jul 29 21:33 public_html

-rw-rw-r-- 1 root root 10 Jul 29 21:39 redhat.txt

-rw-rw-r-- 1 root root 10 Jul 28 22:53 test.txt

# upload some files to remote server

sftp> put *.txt

Uploading test.txt to /root/test.txt

test.txt 100% 10 0.0KB/s 00:00

Uploading test2.txt to /root/test2.txt

test2.txt 100% 0 0.0KB/s 00:00

sftp> ls -l

drwxrwxr-x 2 root root 6 Jul 29 21:33 public_html

-rw-rw-r-- 1 root root 10 Jul 29 21:39 redhat.txt

-rw-rw-r-- 1 root root 10 Jul 29 21:45 test.txt

-rw-rw-r-- 1 root root 10 Jul 29 21:46 test2.txt

# download a file from remote server

sftp> get test.txt

Fetching /root/test.txt to test.txt

/root/test.txt 100% 10 0.0KB/s 00:00

# download some files from remote server

sftp> get *.txt

Fetching /root/redhat.txt to redhat.txt

/root/redhat.txt 100% 10 0.0KB/s 00:00

Fetching /root/test.txt to test.txt

/root/test.txt 100% 10 0.0KB/s 00:00

Fetching /root/test2.txt to test2.txt

/root/test2.txt 100% 10 0.0KB/s 00:00

# create a directory on remote server

sftp> mkdir testdir

sftp> ls -l

drwxrwxr-x 2 root root 6 Jul 29 21:33 public_html

-rw-rw-r-- 1 root root 10 Jul 29 21:39 redhat.txt

-rw-rw-r-- 1 root root 10 Jul 29 21:45 test.txt

-rw-rw-r-- 1 root root 10 Jul 29 21:46 test2.txt

drwxrwxr-x 2 root root 6 Jul 29 21:53 testdir

# delete a directory on remote server

sftp> rmdir testdir

rmdir ok, `testdir' removed

sftp> ls -l

drwxrwxr-x 2 root root 6 Jul 29 21:33 public_html

-rw-rw-r-- 1 root root 10 Jul 29 21:39 redhat.txt

-rw-rw-r-- 1 root root 10 Jul 29 21:45 test.txt

-rw-rw-r-- 1 root root 10 Jul 29 21:46 test2.txt

# delete a file on remote server

sftp> rm test2.txt

Removing /root/test2.txt

sftp> ls -l

drwxrwxr-x 2 root root 6 Jul 29 21:33 public_html

-rw-rw-r-- 1 root root 10 Jul 29 21:39 redhat.txt

-rw-rw-r-- 1 root root 10 Jul 29 21:45 test.txt

# execute commands with "![command]"

sftp> !cat /etc/passwd

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin

...

...

redhat:x:1001:1001::/root:/bin/bash

# exit

sftp> quit

221 Goodbye.

3. SSH使用密钥对认证

3.1. 给服务器用户创建密钥对

[root@server1 ~]# ssh-keygen -t rsa

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):

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:r5uV45jQN9JPbbD0qiegffn+d2HPbKAZR1D8lrnwpqk root@server1.smartmap.com

The key's randomart image is:

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

| o. |

| . . |

| . .o|

| ..oo|

| S o.o..|

| ..o o.=o* |

| .oo.O.o=O+o|

| ...X+=+= B|

| *ooE*..o.|

+----[SHA256]-----+

[root@server1 ~]# ll

total 4

-rw-------. 1 root root 1496 Oct 28 11:32 anaconda-ks.cfg

[root@server1 ~]# ls -la

total 28

dr-xr-x---. 3 root root 147 Oct 28 12:31 .

dr-xr-xr-x. 17 root root 244 Oct 28 11:54 ..

-rw-------. 1 root root 1496 Oct 28 11:32 anaconda-ks.cfg

-rw-------. 1 root root 326 Oct 28 11:54 .bash_history

-rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout

-rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile

-rw-r--r--. 1 root root 176 Dec 29 2013 .bashrc

-rw-r--r--. 1 root root 100 Dec 29 2013 .cshrc

drwx------ 2 root root 38 Oct 28 12:31 .ssh

-rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc

[root@server1 ~]# cd .ssh/

[root@server1 .ssh]# ll

total 8

-rw------- 1 root root 1679 Oct 28 12:31 id_rsa

-rw-r--r-- 1 root root 407 Oct 28 12:31 id_rsa.pub

[root@server1 .ssh]# mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys

[root@server1 .ssh]# chmod 600 ~/.ssh/authorized_keys


3.2. 客户机复制服务器的密钥,并应用服务器的密钥登录服务器

[root@server2 ~]# mkdir ~/.ssh

[root@server2 ~]# chmod 700 ~/.ssh

[root@server2 ~]# scp root@192.168.1.101:/root/.ssh/id_rsa ~/.ssh/

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

ECDSA key fingerprint is SHA256:lgN0eOtdLR2eqHh+fabe54DGpV08ZiWo9oWVS60aGzw.

ECDSA key fingerprint is MD5:28:c0:cf:21:35:29:3d:23:d3:62:ca:0e:82:7a:4b:af.

Are you sure you want to continue connecting (yes/no)? yes

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

root@192.168.1.101's password:

id_rsa 100% 1679 79.8KB/s 00:00

[root@server2 ~]# ssh -i ~/.ssh/id_rsa root@192.168.1.101

Last login: Sat Oct 28 12:23:00 2017 from 192.168.1.100

CentOS7系列--2.2CentOS7中配置SSH服务的更多相关文章

  1. CentOS7系列--3.2CentOS7中配置iSCSI服务

    CentOS7配置iSCSI服务 在网络上的存贮服务为iSCSI Target,而连接到iSCSI Target服务的叫iSCSI Initiator 1. 直接配置iSCSI Target服务 1. ...

  2. CentOS7系列--3.1CentOS7中配置NFS服务

    CentOS7配置NFS服务 1. 配置NFS服务器端 1.1. 安装nfs-utils软件 [root@server1 ~]# yum install -y nfs-utils Loaded plu ...

  3. CentOS7系列--5.2CentOS7中配置和管理Docker

    CentOS7配置和管理Docker Docker是操作系统级别的虚拟化工具,它能自动化布署在容器中的应用 1. 安装Docker 1.1. 安装Docker相关软件 [root@server1 ~] ...

  4. CentOS7系列--5.1CentOS7中配置和管理KVM

    CentOS7配置和管理KVM 安装与配置虚拟化软件KVM ( Kernel-based Virtual Machine ) + QEMU,它要求计算机的CPU支持Intel VT or AMD-V功 ...

  5. CentOS7系列--5.3CentOS7中配置和管理Kubernetes

    CentOS7配置和管理Kubernetes Kubernetes(k8s)是自动化容器操作的开源平台,这些操作包括部署,调度和节点集群间扩展.如果你曾经用过Docker容器技术部署容器,那么可以将D ...

  6. stackstorm docker中配置ssh免密码登录方式

    在docker中配置st2的ssh登录方式折腾了好久,今天终于彻底搞懂了如何重启容器后也不丢失之前的配置,只要容器起来后就可以正常ssh 执行st2中的remote-shell-script 和rem ...

  7. 如何在ubuntu中启用SSH服务

    如何在ubuntu14.04 中启用SSH服务 开篇科普:  SSH 为 Secure Shell 的缩写,由 IETF 的网络工作小组(Network Working Group)所制定:SSH 为 ...

  8. docker中安装ssh服务

    系统:Debian Docker 目标:在docker(debian系统)中安装ssh服务,实现远程登陆和控制docker 步骤: 初始状态:通过docker pull debian得到的一个debi ...

  9. Sco Openserver下 配置SSH服务(图解)

    Sco Openserver下 配置SSH服务 好久没玩儿Sco Unix系统了,春节过后为邮政系统的一个朋友调试系统( 装了个远程服务) ,这两天将安装过程回忆了一下,总结出来给大家分享. 本试验需 ...

随机推荐

  1. pg_stat_statements跳过的坑

    pg_stat_statements跳过的坑 原本以为只是一个简单的插件扩展安装,三下五除二就能搞定,结果搞了很久也没找到问题所在.首先pg_stat_statements已经安装成功,且已经能够使用 ...

  2. 杭电OJ第11页2000-2009道题(C语言)

    1. ASCII码排序 问题描述 输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符 Input: 输入数据有多组,每组占一行,有三个字符组成,之间无空格 Output: 对于每组输入 ...

  3. Maven使用常用命令

    > mvn clean 删除target文件夹 > mvn clean test 编译测试代码,默认被放到target/test-classes文件夹下面 > mvn clean c ...

  4. (转)Jupyter notebook入门教程(上,下)

    https://blog.csdn.net/red_stone1/article/details/72858962------上 https://blog.csdn.net/red_stone1/ar ...

  5. 【Java并发编程】:并发新特性—Executor框架与线程池

    Executor框架简介 在Java5之后,并发编程引入了一堆新的启动.调度和管理线程的API.Executor框架便是Java 5中引入的,其内部使用了线程池机制,它在java.util.cocur ...

  6. 【转】如何选择Html.RenderPartial和Html.RenderAction

    Html.RenderPartial与Html.RenderAction这两个方法都是用来在界面上嵌入用户控件的. Html.RenderPartial是直接将用户控件嵌入到界面上: <%Htm ...

  7. 《Algorithms算法》笔记:优先队列(1)——API和初等实现

    1.优先队列的API和初等实现 做一个总结: 栈 :先进后出 队列 :先进先出 随机队列 : 随机出 优先队列:每次出来的是最大值或最小值 1.1优先队列的API 优先队列在很多场合都有用, 比如:在 ...

  8. mysql RC下不存在则插入

    mysql版本:5.7 目的:在RC下,name列上仅有key索引,并发插入name时不出现重复数据 RC不加gap lock,并且复合select语句是不加锁的快照读,导致两个事务同时进行都可插入, ...

  9. Memcached理解笔记4---应对高并发攻击

    近半个月过得很痛苦,主要是产品上线后,引来无数机器用户恶意攻击,不停的刷新产品各个服务入口,制造垃圾数据,消耗资源.他们的最好成绩,1秒钟可以并发6次,赶在Database入库前,Cache进行Mis ...

  10. Oracle驱动classes12.jar 与ojdbc14.jar的区别

    简单的说,如果使用jdk1.2和jdk1.3就使用classes12.jar:如果使用的jdk1.4和jdk1.5的,就选用ojdbc14.jar. 驱动包classes12.jar用于JDK 1.2 ...