ssh服务配置

简介:

SSH的英文全称是Secure SHell。通过使用SSH,你可以把所有传输的数据进
行加密,这样“中间人”这种攻击方式就不可能实现了,而且也能够防止DNS和IP
欺骗。还有一个额外的好处就是传输的数据是经过压缩的,所以可以加快传输的
速度。SSH有很多功能,它既可以代替telnet,又可以为ftp、pop、甚至ppp提供一
个安全的“通道”。

1.ssh的key认证(本机生成KEY)
    所谓的密钥认证,实际上是使用一对加密字符串,一个称为公钥(public key),
任何人都可以看到其内容,用于加密;另一个称为密钥(private key),只有拥有者
才能看到,用于解密。 通过公钥加密过的密文使用密钥可以轻松解密,但根据公
钥来猜测密钥却十分困难。
  ssh 的密钥认证就是使用了这一特性。服务器和客户端都各自拥有自己的公钥
和密钥。
在认证之前,客户端需要通过某种方法将公钥 Ac 登录到服务器上。

#######生成key###########
[test@foundation0 ~]$ ssh-keygen ###生成公钥和私钥的工具
Generating public/private rsa key pair.
Enter file in which to save the key (/home/test/.ssh/id_rsa):『enter』 ###指定加密字符
保存文件,使用默认
Created directory '/home/test/.ssh'.
Enter passphrase (empty for no passphrase): ###密码,必须大于4位
Enter same passphrase again:
Your identification has been saved in /home/test/.ssh/id_rsa.
Your public key has been saved in /home/test/.ssh/id_rsa.pub.
The key fingerprint is: ###确认密码
a5:4f:02:51:68:59:f4:e8:e3:c5:91:1f:6f:86:99:06 test@foundation0.ilt.example.com
The key's randomart image is:
+--[ RSA 2048]----+
|      .*+        |
|      +. o .     |
|     .. . E .    |
|       o + + *   |
|        S + * +  |
|       . * . o   |
|        . .      |
|                 |
|                 |
+-----------------+
[test@foundation0 .ssh]$ pwd
/home/test/.ssh ###生成密钥存放位置
[test@foundation0 .ssh]$ ls
id_rsa  id_rsa.pub ####id_rsa位私钥,id_rsa.pub位公钥

2.使用key加密目标主机的目标用户
[test@foundation0 ~]$ssh-copy-id -i /home/test/.ssh/id_rsa.pub test@172.25.254.100

The authenticity of host '172.25.254.100 (172.25.254.100)' 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
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are
already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is t
o install the new keys
westos@172.25.254.100's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'westos@172.25.254.100'"
and check to make sure that only the key(s) you wanted were added.

ssh-copy-id     ####上传key的工具
-i     ####指定使用的公钥
/home/test/.ssh/id_rsa.pub #####使用公钥的名称
westos ####被管理的目标用户
172.25.254.100    ####被管理用户所在主机的ip

authorized_keys ###此文件在目标用户加目录的.ssh中,这个文件就是目标
用户被加密的标识,文件内容位公钥内容。

3.传文件(分发私钥)
scp /home/test/id_rsa client@12.23.21.23:/home/client/.ssh   #把当前主机中的id_rsa文
件推送到

4.远程文件传输:scp,rsync

ssh(远程shell)
sftp(软件)

scp ##远程复制
-v 显示进度-C 压缩传输选项-P 指定端口-4 强行使用 IPV4 地址-6 强行使用 IPV6 地
址-i 指定私钥文件路径-r 遍历路径复制-l 限制最大传输带宽,单位是Kb/s
scp file user@ip:/directory ##上传文件
scp -r dir user@ip:/directory ##长传目录
scp user@ip:/filename /direcotry ##下载文件
scp -r user@ip:/directory /direcotry ##下载目录


scp是复制新建的过程
rsync是镜像的过程(同步,不能同步链接)

rsync file|direcotry user@ip:/directory
rsync user@ip:/directory /directory
-r ##目录
-l ##不忽略链接
-p ##不忽略权限
-t ##不忽略时间戳
-g ##不忽略组信息
-o ##不忽略用户信息
-D ##不忽略设备文件

5.sshd服务的简单配置
systemctl restart sshd ###从新加载配置

5.1.修改/etc/ssh/sshd_config,具体如下:
Protocol 2  #只支持SSH2协议Port <端口号>  #修改默认端口号
MaxStartups 5    #同时允许5个尚未登录的SSH联机
MaxAuthTries  3   #最大登录尝试次数为3
ServerKeyBits 1024          #将ServerKey强度改为1024比特
PermitEmptyPasswords no     #禁止空密码进行登录
ChallengeResponseAuthentication no #禁用s/key密码
UsePAM no                   #不通过PAM验证
PermitRootLogin no           #禁止root远程登录
PasswordAuthentication no   #不允许密码方式的登录
RSAAuthentication no         #不允许RSA认证,只针对SSH1
PubkeyAuthentication yes     #允许公钥认证
AuthorizedKeysFile .ssh/authorized_keys #保存公钥的认证文件
UsePrivilegeSeparation yes    #用户权限设置
SyslogFacility AUTH #记录SSH登录情况
LogLevel INFO    #记录等级为
INFOPrintMotd yes    #登录成功后显示/etc/motd 文件的内容
PrintLastLog no   #不显示上次登录信息
Compression yes    #是否压缩命令
KeepAlive yes    #防止死连接
StrictModes yes   #接受连接请求前对用户主目录和相关的配置文件进行宿主和权限
检查
UseDNS no  #不使用DNS反解
AllowUsers <用户名>  #允许通过远程访问的用户,多个用户以空格分隔
AllowGroups <组名>   #允许通过远程访问的组,多个组以
空格分隔
DenyUsers <用户名>   #禁止通过远程访问的用户,多个用户以空格分隔
DenyGroups <组名>    #禁止通过远程访问的组,多个组以空格分隔

5.2、如果需要限制来路IP的话,可以修改/etc/hosts.deny和/etc/hosts.allow两个文件,
通过添加sshd:来限制或允许SSH远程链接IP。



本文转自willis_sun 51CTO博客,原文链接:http://blog.51cto.com/willis/1846791,如需转载请自行联系原作者


相关文章
|
11天前
|
消息中间件 安全 Unix
SSH配置多台服务器之间的免密登陆以及登陆别名
SSH配置多台服务器之间的免密登陆以及登陆别名
21 1
|
3月前
|
Ubuntu 安全 网络安全
百度搜索:蓝易云【Ubuntu系统SSH服务端配置】
现在,你已经成功在Ubuntu系统上配置了SSH服务端。这将允许其他计算机通过SSH协议连接到你的Ubuntu系统,并进行远程管理和操作。请注意,远程访问有安全风险,建议在生产环境中采取必要的安全措施来保护系统。
39 3
|
3月前
|
Ubuntu Linux 网络安全
【计算机网络】SSH 服务安装
【1月更文挑战第10天】【计算机网络】SSH 服务安装
|
5月前
|
Ubuntu 网络安全 Docker
Ubuntu 安装与配置ssh (docker)
Ubuntu 安装与配置ssh (docker)
110 0
|
5月前
|
监控 数据可视化 安全
Linux——怎样使用SSH服务实现远程UI界面本地显示
需求场景 最近几天需要实现软件的远程监控,但是实际场景又不能使用向日葵、VNC、AnyDesk、以及其他的监视软件,并且软件的整体设计也没有这块的数据上行设计。
182 0
|
2月前
|
安全 Shell 网络安全
【Git】TortoiseGit(小乌龟)配置SSH和使用
【Git】TortoiseGit(小乌龟)配置SSH和使用
146 0
|
6天前
|
网络协议 安全 Shell
配置ssh服务
配置ssh服务
|
14天前
|
Shell 网络安全 开发工具
配置SSH时候,Permission denied问题解决方法
配置SSH时候,Permission denied问题解决方法
30 4
|
1月前
|
安全 Shell 网络安全
ssh配置无密码验证
ssh配置无密码验证要在SSH中配置无密码验证,您需要使用公钥验证【2月更文挑战第18天】
39 1
|
1月前
|
Shell 网络安全 数据安全/隐私保护
配置多个SSH公钥流程
配置多个SSH公钥流程