当前位置: 首页 > Linux

Serverfromscratch(1D)-user+sudo+vnc

时间:2023-04-06 23:41:06 Linux

简介我开始这个系列是为了系统地学习和记录企业应用服务环境搭建和应用部署的全过程。本系列将精彩展示如何通过一点一点的砌砖,搭建一座高楼。它可能包含一些比较初级的内容。如果你已经掌握了,可以跳过,选择你关心的章节。本系列开篇的背景是一位徐姓朋友慷慨赞助我一台腾讯云服务器,CentOS7.4+单核+2G内存。配置有点低,不过考虑到自己玩玩也无妨,下面开始我们万里长征的第一步吧。创建用户、组,sudoroot用户1,创建组fzu[root@VM_60_202_centos~]#groupaddfzu--creategroupfzu[root@VM_60_202_centos~]#useradd-gfzu-mkerry--createuserkerry并加入fzu[root@VM_60_202_centos~]#passwdkerry--设置/修改kerry的密码,会弹出输入密码,然后确认密码2,创建/u01目录,将/u01的权限给kerry[root@VM_60_202_centos~]#mkdir/u01[root@VM_60_202_centos~]#chown-Rkerry:fzu/u013,给kerry用户sudo,/etc/sudoers文件只能用专用的visudo编辑器编辑,执行commandvisudo[root@VM_60_202_centos~]#visudo--输入/etc/sudoers的文本--添加如下代码,以kerry用户登录时可以使用sudo,不需要输入kerry密码进行验证。kerryALL=(ALL)NOPASSWD:ALLInstallVNC1,如果服务器安装了VNC先试试[root@VM_60_202_centos~]#rpm-qtigervnc如果没有安装tigervnc-server,会直接出现[root@VM_60_202_centos~]#未安装包tigervnc[root@VM_60_202_centos~]#packagetigervnc-server未安装2。如果没有安装X-Windows桌面,先安装Xwindows[root@VM_60_202_centos~]#yumcheck-update[root@VM_60_202_centos~]#yumgroupinstall"XWindowSystem"[root@VM_60_202_centos~]#yuminstallgnome-classic-sessiongnome-terminalnautilus-open-terminalcontrol-centerliberation-mono-fonts[root@VM_60_202_centos~]#unlink/etc/systemd/system/default.target[root@VM_60_202_centos~]#ln-sf/lib/systemd/system/graphical.target/etc/systemd/system/default.target[root@VM_60_202_centos~]#reboot3,安装VNC包[root@VM_60_202_centos~]#yuminstalltigervnc-server-y修改配置信息,创建文件夹vncserver@:1.serviceunder/etc/systemd/system/将示例配置文件从/lib/systemd/system/vncserver@.service复制到它[root@VM_60_202_centos~]#cp/lib/systemd/system/vncserver@.service/etc/systemd/system/vncserver@:1.service然后打开这个配置文件/etc/systemd/system/vncserver@:1.service替换默认用户名找到这一行ExecStart=/sbin/runuser-l-c"/usr/bin/vncserver%i"PIDFile=/home//.vnc/%H%i.pid这里我用的是root用户直接登录,所以我换成:ExecStart=/sbin/runuser-lroot-c"/usr/bin/vncserver%i"PIDFile=/root/.vnc/%H%i.pid如果是其他用户,比如johnreplacement如下:ExecStart=/sbin/runuser-l-c"/usr/bin/vncserver%i"PIDFile=/home//.vnc/%H%i.pidreloadsystemd[root@VM_60_202_centos~]#systemctldaemon-reload--Reloadsystemd[root@VM_60_202_centos~]#vncpasswd--设置VNC密码由于我这边的Centos7使用了iptable防火墙,所以需要修改配置:[root@VM_60_202_centos~]#vim/etc/sysconfig/iptables--Add-AINPUT-mstate--stateNEW-mtcp-ptcp--dport5900:5903-jACCEPT[root@VM_60_202_centos~]#service在iptables文件iptables重启--如果你使用Centos7默认防火墙重启iptable可能需要[root@VM_60_202_centos~]#firewall-cmd--permanent--add-servicevnc-server[root@VM_60_202_centos~]#systemctlrestartfirewalld.service设置启动并默认开启VNC[root@VM_60_202_centos~]#systemctl启用vncserver@:1.service[root@VM_60_202_centos~]#systemctl启动vncserver@:1.service