您的位置:首页 > 编程语言 > PHP开发

Redhat7安装VNC服务端和FTP服务端实现远程控制

2017-09-11 18:05 639 查看
VNC作为一种非常成熟使用方便的远程桌面系统,使用非常广泛

首先要注意在安装Redhat的时候要安装图形化界面GNU——KDE和FTP服务器



安装VNC的过程非常简单

1、首先将光盘放入光驱,观察光驱的挂载点,然后将本地的yum源指向光驱。

假设现在的光驱挂载点为 /run/media/alex/RHEL-7.2 Server.x86_64/,太长了所以我使用软连接把这个目录连接到了/opt/rhel下面(ln -s   /run/media/alex/RHEL-7.2\ Server.x86_64/  /opt/rhel),那么现在需要在/etc/yum.repos.d/目录下建立一个新文件,rhel-source.repo,内容如下。

[base]
name=Red Hat Enterprise Linux $releasever - $basearch - Source
baseurl=file:///opt/rhel
enabled=1
gpgcheck=1
gpgkey=file:///opt/rhel/RPM-GPG-KEY-redhat-release


这个文件就指明了一个名为“base”的yum源,它指向光盘(并非光盘里面的Packages文件夹),使用baseurl=file...这种方式可以指向本地的文件。同时这里也可以支持http或者ftp格式,可以在局域网内搭建yum源服务器。

同时gpg证书也指向光盘中的gpg证书。注意如果光盘不是自动挂载的,或者你只有一个.iso文件,那么也可以把这个.iso文件上传到Redhat服务器上,然后使用mount -o loop xxx.iso的方式进行挂载。

配置完成之后刷新一下yum

yum clean all
yum update
如果配置的路径正确,那么此处会更新yum源,如果路径填写错误或者挂载出现问题,跑不了几行就会报ERROR

有了光盘的yum源之后再安装就轻而易举了,首先检查一下VNC是否被安装过了

rpm -qa vnc*


如果没有输出说明没有被安装过,那么我们现在就可以安装了

yum -y install vnc*
如果你之前yum配置的没有问题,那么此时安装应该是非常顺畅

依赖关系解决

====================================================================================================================================================
Package                                  架构                            版本                                  源                             大小
====================================================================================================================================================
正在安装:
tigervnc                                 x86_64                          1.3.1-3.el7                           base                          210 k
tigervnc-server                          x86_64                          1.3.1-3.el7                           base                          202 k
为依赖而安装:
fltk                                     x86_64                          1.3.0-13.el7                          base                          654 k
tigervnc-icons                           noarch                          1.3.1-3.el7                           base                           35 k

事务概要
====================================================================================================================================================
安装  2 软件包 (+2 依赖软件包)

总下载量:1.1 M
安装大小:2.6 M


安装完毕之后,配置一个密码就可以用了。下面这个密码就是客户端连接所用的密码,和本地user的密码可以不同

vncpasswd


下面就可以启动VNC服务器了,注意当前命令行是哪个用户那么远程登录之后就是哪个用户,权限也是一致的

vncserver
每次执行都会新建一个vnc服务端,第一个使用5901端口,第二个5902以此类推。

windows做客户端的话,只需要安装一个VNCViewer,填入IP和端口,写上上面录入的密码就可以登录图形化界面





安装FTP不复杂,但是装FTP主要就是为了在SSH之外查看和修改服务器上的文件的,一般都会做成匿名访问,拥有很高的权限,可以查看,修改,删除任意一个服务器上的文件。主要任务就是修改配置文件/etc/vsftpd/vsftpd.conf,修改后如下

# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES

local_root=/
chroot_local_user=YES
anon_root=/

#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
anon_upload_enable=YES
anon_world_readable_only=NO
anon_umask=022
anon_other_write_enable=YES

#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/xferlog
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# 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
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=NO
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
# Make sure, that one of the listen options is commented !!
listen_ipv6=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES


启动vsftpd的命令是:

service vsftpd restart


但是光这样是无法像root一样访问服务器的,因为对于RedHat还有一个selinux用来加强安全的,必须要关闭它

方法1:修改/etc/selinux/config文件中的SELINUX="" 为 disabled ,然后重启。
方法2:用命令setenforce 0,无需重启。(setenforce的格式:setenforce [ Enforcing | Permissive | 1 | 0 ])

然后就可以自由的操作FTP了。

如果你不想任何一个人通过浏览器就可以匿名访问你的FTP主机,那么可以加上下面两行,只允许除root以外的限定用户通过账号密码登录

userlist_deny=NO
userlist_file=/etc/vsftpd/user_list
然后你可以修改/etc/vsftpd/user_list来限定访问的用户,注意考虑/etc/vsftpd/ftpusers这个文件里面记录了黑名单。

最后要注意要对相应的要通过FTP传输的文件赋予相关访问权限。

比如如下三个文件:

-rw-------.   1 root root   126 9\u6708  12 18:39 ftpusers

-rw-------.   1 root root   366 9\u6708  12 18:41 user_list

-rw-------.   1 root root  5206 9\u6708  12 19:08 vsftpd.conf

-rwxr--rw-.   1 root root   338 8\u6708   3 2015 vsftpd_conf_migrate.sh

那么对于FTP用户来说,只能读取 vsftpd_conf_migrate.sh这一个文件,其余三个文件均无法读写。原因是

-rw------- 前三个是文件所有者的权限,中间三个是与文件所有者同组的权限,最后三位是其他用户的权限,FTP属于其他用户(如果你使用Linux的用户登录,那么要注意是否同组的问题),所以最后三位需要为rw-,一般执行如下命令

chmod o+r+w -R /xxx/xxx/*

意思就是对于其他用户(o)对某个目录下所有文件和递归后的文件,全部添加r和w权限,当然这样也是比较危险的。

另外RedHat安装完毕之后会自动打开防火墙,封锁除22以外的所有端口,所以还需要把防火墙暂时关闭

systemctl stop firewalld

永久关闭
systemctl disable firewalld

开启防火墙
systemctl enable firewalld
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: