为服务器创建上传资料的用户:
为了将本地的 网站文件上传到服务器,需要创建一个上传文件并维护网站的用户,那这个用户就是本人dafu了。
#adduser dafu
#passwd dafu
输入两次密码,这个用户就创建OK了,而且系统还在/home目录下给创建了一个独立目录,这个目录就是俺的家了。
有了用户还不行,基本上还不能做任何事,毕竟安全第一嘛,得给你个权限,比如要上传文件,就得有服务器某个目录的写权限。
[root@VM-0-16-centos dafu]# chmod -v u+w /etc/sudoers
mode of ‘/etc/sudoers’ changed from 0440 (r--r-----) to 0640 (rw-r-----)
[root@VM-0-16-centos dafu]# cd /etc
[root@VM-0-16-centos etc]# vi sudoers
[root@VM-0-16-centos etc]# chmod -v u-w sudoers
mode of ‘sudoers’ changed from 0640 (rw-r-----) to 0440 (r--r-----)
现在用户有了,上传的权限也开通了,现在打开FTP客户端连接,发现连接不上。。。。。
哦,服务器端还没有安装FTP Server呢,那接下来就到服务器上看看情况
[root@VM-0-16-centos ~]# service vsftpd status
Redirecting to /bin/systemctl status vsftpd.service
Unit vsftpd.service could not be found.
[root@VM-0-16-centos ~]#
Centos 系统确实是默认没有FTP功能的,那就安装一个吧,很简单,敲上这个命令一会就给安装好了。
[root@VM-0-16-centos ~]# yum install -y vsftpd
将FTP运行起来并将它设置为开机自动运行。
[root@VM-0-16-centos ~]# systemctl start vsftpd 启动服务
[root@VM-0-16-centos ~]# service vsftpd status 查看状态
[root@VM-0-16-centos ~]# systemctl enable vsftpd 设置为开机自动运行
到此,我就可以通过FTP客户端访问我的目录(/home/dafu),并能上传文件了。
如果你不小心点开向上的目录,你会发现你可以查看不少系统的其他一些目录,这就很危险了,权限有点大了,我们要设置一下,防止其看到一些这个用户不该看到了东西,让他只能看自己的目录。我们要修改FTP的配置文件,进行安全设置。
[root@VM-0-16-centos home]#vi /etc/vsftpd/vsftpd.conf
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
# chroot_local_user=YES 把前面的#删掉
另外,为了安全,还要禁止匿名登录。
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
# anonymous_enable=YES 将这行注释掉
设置完毕,保存,退出,重启,dafu就只能访问自己的目录了。
[root@VM-0-16-centos home]# service vsftpd restart
Redirecting to /bin/systemctl restart vsftpd.service
精减开发网站的内容,删除测试用的图片文章等内容,将整个开发网站的目录 上传到服务器,上述的操作是在宿主主机上进行的,我们先将本地文件传到宿主服务器上,然后再在服务器上将上传的文件复制到Docker容器内,才能实现应用的运行。
下一篇,将是进行Docker 操作,Docker的好处就不用多说了,方便啊。
最后修改于:4年前