vnc怎么删除端口,vnc怎么删除端口的3个命令

蜗牛vpsvps教程2020-08-075410

大家在使用vnc的时候,经常会使用到vnc端口修改,用户添加删除,批量启动的操作,,本文主要介绍的就是在Linux系统中如何进行vnc端口修改,用户添加删除,批量启动的操作的教程。

如果觉得太麻烦的话可以使用IIS7服务器管理工具,可以批量连接并管理VNC服务器 作为服务器集成管理器,它最优秀的功能就是批量管理windows与linux系统服务器、vps。能极大的提高站长及服务器运维人员工作效率。同时iis7服务器管理工具还是vnc客户端,服务器真正实现了一站式管理,可谓是非常方便。

IIS7服务器管理工具界面如下:

vnc怎么删除端口,vnc怎么删除端口的3个命令  第1张
vnc怎么删除端口,vnc怎么删除端口的3个命令  第2张

yum -y install tiger-server

#!/usr/bin/env bash

config_file="/etc/sysconfig/vncservers"

port_file="/root/.vnc_port"

vncserver_file=`which vncserver`

#sed -i 's/5900\ +/12000\ +/g' $vncserver_file

#sed -i 's/12000\ +/5900\ +/g' $vncserver_file

###端口修改成起始端口

function port_init {

last_port=5900

if [[ -e $port_file ]];then

old_port=`cat $port_file`

sed -i "s/$old_port\ +/5900\ +/g" $vncserver_file

echo "5900" > $port_file

fi

}


###修改端口

function modfy_port {

last_port=$1

if [[ $last_port == "" ]];then

echo "Please input the port you want "

else

if [[ -e $port_file ]];then

old_port=`cat $port_file`

sed -i "s/$old_port\ +/$last_port\ +/g" $vncserver_file

echo $last_port > $port_file

else

sed -i "s/5900\ +/$last_port\ +/g" $vncserver_file

echo $last_port > $port_file

fi

fi

}

###添加用户

function adduser {

if [[ $1 == "" ]];then

echo "Please input a user name"

else

user_num=`grep -w VNCSERVERS $config_file|awk '{print $NF}'|cut -d":" -f1`

latest_user_num=`expr $user_num + 1`

last_user=`grep -w VNCSERVERS $config_file|awk '{print $NF}'|awk -F'"' '{print $1}'`

sed -i "s/$last_user/$last_user\ $latest_user_num:$1/" $config_file

echo "VNCSERVERSVNCSERVERARGS[$latest_user_num]=\"-geometry 1600x900 -alwaysshared\"" >> $config_file

useradd $1

echo "****"|passwd --stdin $1

fi

}

###删除用户

function deleteuser {

if [[ $1 == "" ]];then

echo "Please input the username to delete"

else

delete_user_match=$(egrep -w "[0-9]{1,3}:$1" $config_file|wc -l)

if [[ $delete_user_match -ne 1 ]];then

echo "Please make sure the user name is correct"

else

delete_user_num=`egrep -w "[0-9]{1,3}:$1" $config_file|awk -F":$1" '{print $1}'|awk '{print $NF}'`

sed -i "s/\ $delete_user_num:$1//" $config_file

sed -i "s/.*\[$delete_user_num\].*//" $config_file

userdel -r $1

fi

fi

}

###服务启动

function start {

#user_list=`grep -w VNCSERVERS $config_file|awk -F'"' '{print $2}'|sed 's/[0-9]\+://g' `

user_list=`grep -w VNCSERVERS $config_file|awk -F'"' '{print $2}'`

echo $user_list

for i in $user_list

do

user_port=$(echo $i|cut -d":" -f1)

user=$(echo $i|cut -d":" -f2)

#su - $user -c "vncserver -kill :$user_port"

expect -c "

set timeout 1200;

spawn /usr/bin/su - $user -c "vncserver\ \:$user_port"

expect {

"Password:" {send "***"\r;exp_continue}

"Verify:" {send "***"\r;}

}

expect eof;"

done

}

function stop {

user_list=`ps aux |grep vnc |grep rfbport |awk '{print $1 $12}'`

for i in $user_list

do

user_port=$(echo $i|cut -d":" -f2)

user=$(echo $i|cut -d":" -f1)

su - $user -c "vncserver -kill :$user_port"

done

}

case $1 in

adduser)

adduser $2

;;

deleteuser)

deleteuser $2

;;

stop)

stop

;;

start)

start

;;

default_port)

port_init

;;

modify_port)

modfy_port $2

;;

*)

echo -e "Usage:\ncommands:\n adduser #define:please input a user name,Don't use pure numbers\n deleteuser #define:please input a complete user name\n start #define:start all service\n stop #define:stop all service\n default_port #define:Modify port to default start segment\n modify_port #define:Modify the port to the segment you want"

;;

esac

vnc怎么删除端口,vnc怎么删除端口的3个命令  第3张

评论

有免费节点资源,我们会通知你!加入纸飞机订阅群

×
天气预报查看日历分享网页手机扫码留言评论Telegram