Unit7 sshd服务补充;文件的上传及下载

sshd的安全设定

##########小技巧###########

可以在真机的终端上ssh链接虚拟机

然后ctrl+shift+t打开新的终端页

在虚拟机上的操作就可以很容易的复制到真机上

虚拟机ip:172.25.254.80  ##在虚拟机上配置好的

[kiosk@foundation30 ~]$ ssh [email protected]

##########################

sshd的配置文件存放在

/etc/ssh/sshd_config

主要可以进行三种更改操作

1.是否允许用户通过登陆系统密码作为sshd的认证

vim /etc/ssh/sshd_config   ##在78行进行修改 PasswordAuthentication yes->no  
systemctl restart sshd.service  ##重启sshd的配置

修改后在客户端的用户student无法通过密码连接服务器

[root@vm138 ~]# su - student

[student@vm138 ~]$ ssh [email protected]

The authenticity of host '172.25.254.88 (172.25.254.88)' 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

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

Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

2.root用户权限

 修改第48行 PermitRootLogin no  ##关闭后客户端的用户访问服务器的root用户必须使用密码,不能用sshd认证

systemctl restart sshd.service

##此时已经预先分配过公钥和私钥

[root@vm138 ~]# ssh [email protected]

[email protected]'s password:         ##需要输入密码

可以直接通过sshd钥匙登陆

 48 PermitRootLogin yes      

[root@vm138 ~]# ssh [email protected]

Last login: Fri Jan 11 22:55:41 2019 from 172.25.254.138

3.黑白名单

在第52行进行添加

denyusers student   ##sshd用户的黑名单

allowusers student   ##sshd用户的白名单

表示只有服务器端的student用户可以使用sshd操作,从客户端进行安全设定

比如你给服务端的root加个sshd的锁,在客户端无法借用钥匙访问root,因为root不在白名单

添加ssh登陆信息

 vim /etc/motd   #更改服务器上所有用户的登陆信息

[root@server88 ~]# cat /etc/motd

Link Start!

[student@vm138 ~]$ ssh [email protected]

[email protected]'s password:

Last login: Sat Jan 12 00:49:58 2019

Link Start!

用户登录审计

[root@server88 ~]# w      #查看正在使用当前系统的用户

 00:57:23 up  3:17,  3 users,  load average: 0.00, 0.01, 0.05

USER     TTY        LOGIN@   IDLE   JCPU   PCPU WHAT

root     :0        21:41   ?xdm?   2:32   0.09s gdm-session-worker [pam/gdm-password]

root     pts/1     22:37    3.00s  0.05s  0.05s -bash

student  pts/0     00:51    5:27   0.02s  0.02s -bash

[root@server88 ~]# w -f    #查看使用来源

 00:58:20 up  3:18,  3 users,  load average: 0.00, 0.01, 0.05

USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT

root     :0       :0               21:41   ?xdm?   2:32   0.09s gdm-session-worker [pam/gdm-password]

root     pts/1    172.25.254.38    22:37    4.00s  0.05s  0.05s -bash

student  pts/0    172.25.254.138   00:51    6:24   0.02s  0.02s -bash

[root@server88 ~]# last  #查看使用过并推出的用户信息 /var/log/wtmp
[root@server88 ~]# lastb   #查看试图登陆却没有成功的用户 /var/log/btmp

root     ssh:notty    172.25.254.138   Sat Jan 12 00:48 - 00:48  (00:00)    

root     ssh:notty    172.25.254.138   Sat Jan 12 00:47 - 00:47  (00:00)    

root     ssh:notty    172.25.254.138   Sat Jan 12 00:47 - 00:47  (00:00)    

root     ssh:notty    172.25.254.138   Sat Jan 12 00:46 - 00:46  (00:00)    

root     ssh:notty    172.25.254.138   Sat Jan 12 00:46 - 00:46  (00:00)    

root     ssh:notty    172.25.254.138   Sat Jan 12 00:46 - 00:46  (00:00)    

root     ssh:notty    172.25.254.88    Sat Jan 12 00:29 - 00:29  (00:00)    

root     ssh:notty    172.25.254.88    Sat Jan 12 00:28 - 00:28  (00:00)    

文件在系统中的传输

scp

1.上传

  scp file(已存在) user@ip:/dir(存在的目录)  ##传输文件

  scp dir(已存在) user@ip:/dir(存在的目录)   ##传输目录

2.下载

[root@vm138 ~]# scp [email protected]:/root/Desktop/examdocs .
examdocs                               100% 2959     2.9KB/s   00:00

对目录操作需要加上-r

远程同步

rsync #远程同步(速度快,默认忽略文件属性、链接文件、设备文件)

先在/westos下建立file1~file5

[root@vm138 ~]# cd /westos
[root@vm138 westos]# touch file{1..5}
[root@vm138 westos]# ll

total 0

-rw-r--r--. 1 root root 0 Jan 12 02:30 file1

-rw-r--r--. 1 root root 0 Jan 12 02:30 file2

-rw-r--r--. 1 root root 0 Jan 12 02:30 file3

-rw-r--r--. 1 root root 0 Jan 12 02:30 file4

-rw-r--r--. 1 root root 0 Jan 12 02:30 file5

[root@vm138 westos]# rsync * [email protected]:/mnt   ##进行同步

[root@server88 mnt]# ls

file1  file2  file3  file4  file5            ##在server88端得到同步过去的文件

同步目录

[root@vm138 westos]# rsync -r /westos [email protected]:/mnt  #将目录同步过去,在地下可以找到目录内文件

[root@server88 mnt]# ll

total 0

drwxr-xr-x 2 root root 66 Jan 12 02:37 westos

[root@server88 mnt]# ll westos

total 0

-rwxr-xr-x 1 root root 0 Jan 12 02:37 file1

-rwxr-xr-x 1 root root 0 Jan 12 02:37 file2

-rwxr-xr-x 1 root root 0 Jan 12 02:37 file3

-rwxr-xr-x 1 root root 0 Jan 12 02:37 file4

-rwxr-xr-x 1 root root 0 Jan 12 02:37 file5

//////////////////////////////////////////////////////////////////////

[root@vm138 westos]# rsync -r /westos/ [email protected]:/mnt #将目录中内容同步过去

[root@server88 mnt]# ll

total 0

-rwxr-xr-x 1 root root 0 Jan 12 02:40 file1

-rwxr-xr-x 1 root root 0 Jan 12 02:40 file2

-rwxr-xr-x 1 root root 0 Jan 12 02:40 file3

-rwxr-xr-x 1 root root 0 Jan 12 02:40 file4

-rwxr-xr-x 1 root root 0 Jan 12 02:40 file5

-p 表示同步权限

[root@vm138 westos]# chmod 777 file{1..5}

[root@vm138 westos]# ll -d

drwxr-xr-x. 2 root root 66 Jan 12 02:30 .

[root@vm138 westos]# ll

total 0

-rwxrwxrwx. 1 root root 0 Jan 12 02:30 file1

-rwxrwxrwx. 1 root root 0 Jan 12 02:30 file2

-rwxrwxrwx. 1 root root 0 Jan 12 02:30 file3

-rwxrwxrwx. 1 root root 0 Jan 12 02:30 file4

-rwxrwxrwx. 1 root root 0 Jan 12 02:30 file5

[root@vm138 westos]# rsync -p * [email protected]:/mnt     ##同步后保持文件权限

[root@server88 mnt]# ll

total 0

-rwxrwxrwx 1 root root 0 Jan 12 02:35 file1

-rwxrwxrwx 1 root root 0 Jan 12 02:35 file2

-rwxrwxrwx 1 root root 0 Jan 12 02:35 file3

-rwxrwxrwx 1 root root 0 Jan 12 02:35 file4

-rwxrwxrwx 1 root root 0 Jan 12 02:35 file5

-o #同步所有者

-g #同步所属组

-l #同步链接文件

[root@vm138 westos]# ln -s file2 FILE2       #将file2同步到FILE2

[root@vm138 westos]# ll

total 0

-rwxrwxrwx. 2 root root 0 Jan 12 02:30 file1

-rwxrwxrwx. 2 root root 0 Jan 12 02:30 FILE1

-rwxrwxrwx. 1 root root 0 Jan 12 02:30 file2

lrwxrwxrwx. 1 root root 5 Jan 12 02:46 FILE2 -> file2

-rwxrwxrwx. 1 root root 0 Jan 12 02:30 file3

-rwxrwxrwx. 1 root root 0 Jan 12 02:30 file4

-rwxrwxrwx. 1 root root 0 Jan 12 02:30 file5

[root@vm138 westos]# rsync -r /westos/ [email protected]:/mnt    ##不加上-l的话无法进行同步链接

skipping non-regular file "FILE2"

[root@vm138 westos]# rsync -rl /westos/ [email protected]:/mnt

-t #同步文件时间戳,本来同步前后文件的时间会发生变化

-D #同步设备文件

 

猜你喜欢

转载自blog.csdn.net/weixin_41884844/article/details/86440976
今日推荐