2017年10月27日 星期五

Transfer Files/Folders in Linux Using SCP command



scp -Cpr  Source   Destination

ex: scp -Cpr jmt-lab91  tonychung@192.168.0.124:/home/tonychung/Backup88-old/jmt/.VirtualBox/


You can use “-v” parameter to print debug information into the screen. It can help you debugging connection, authentication and configuration problems.

The “-p” parameter will help you on this. An estimated time and the connection speed will appear on the screen.

The “-C” parameter will compress your files on the go. The unique thing is the compression is only happen in the network. When the file is arrived to the destination server, it will returning into the original size as before the compression happen.

Sometimes we need to copy directory and all files / directories inside it. It will be better if we can do it in 1 command. SCP support that scenario using “-r” parameter.

If you choose not to see progress meter and warning / diagnostic messages from SCP, you may disable it using “-q” parameter.


2017年10月25日 星期三

Install Remote Desktop (XRDP)

For Ubuntu 20.04
  Install mate desktop 
  https://linuxconfig.org/how-to-install-mate-desktop-on-ubuntu-20-04-focal-fossa-linux
  Install Mate Xrdp
  Refer to https://www.hiroom2.com/ubuntu-2004-xrdp-mate-en

  


For Ubuntu

Install XFCE4 desktop (bad method, gray screen)

sudo apt-get update
sudo apt-get install xrdp
sudo apt-get install xfce4
echo “xfce4-session” > ~/.xsession
sudo /etc/init.d/xrdp start
sudo /etc/init.d/xrdp status


Install Mate-desktop

sudo apt-get update
sudo apt-get install xrdp
sudo apt-get install mate-core mate-desktop-environment mate-notification-daemon
sudo /etc/init.d/xrdp start
sudo /etc/init.d/xrdp status


Configuring XRDP to use your desktop environment

sudo sed -i.bak '/fi/a #xrdp multiple users configuration \n mate-session \n' /etc/xrdp/startwm.sh



For CentOS

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm


vim /etc/yum.repos.d/xrdp.repo
[xrdp]
name=xrdp
baseurl=http://li.nux.ro/download/nux/dextop/el7/x86_64/
enabled=1
gpgcheck=0


Install xrdp and tigervnc-server, then start xrdp service
yum -y install xrdp tigervnc-server
systemctl start xrdp.service


Check xrdp service
netstat -antup | grep xrdp


Enable service at system startup
systemctl enable xrdp.service


Edit /usr/lib/firewalld/services/xrdp.xml for XRDP (add port 3389)    PS: xrdp.xml will add a "xrdp" item on firewalld GUI
<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>xrdp</short>
  <description>This option allows you to access Remote Desktop Service.</description>
  <port protocol="udp" port="3389"/>
  <port protocol="tcp" port="3389"/>
</service>


Add xrdpservice for firewalld and reload firewalld
sudo firewall-cmd --permanent --add-service=xrdp
sudo firewall-cmd --reload
sudo systemctl status firewalld


Configure SELinux
sudo chcon --type=bin_t /usr/sbin/xrdp
sudo chcon --type=bin_t /usr/sbin/xrdp-sesman



Refer to:
  1. http://c-nergy.be/blog/?p=8952
  2. https://www.interserver.net/tips/kb/install-xrdp-ubuntu-server-xfce-template/
  3. http://www.itzgeek.com/how-tos/linux/centos-how-tos/install-xrdp-on-centos-7-rhel-7.html


Reinstall VirtualBox on Ubuntu & CentOS


For Ubuntu
To remove virtualbox


sudo dpkg --list virtualbox-*
sudo apt autoremove --purge virtualbox*
dpkg -l virtualbox* | grep ^i

Remove all PPAs from sources.list and source.list.d directory


mkdir ~/apt-tmp
sudo mv /etc/apt/sources.list.d/* ~/apt-tmp
Make sure there is nothing except official repositories sources in /etc/sources.list.
And update your sources:
sudo apt update
Now we can search to see which versions are available to install:
apt-cache madison virtualbox | grep -iv sources
Which produces an output like this:
virtualbox | 5.0.32-dfsg-0ubuntu1.16.04.2 | http://mirrors.kernel.org/ubuntu xenial-updates/multiverse amd64 Packages
virtualbox | 5.0.18-dfsg-2build1 | http://mirrors.kernel.org/ubuntu xenial/multiverse amd64 Packages
Then I would install the last version mentioned in xenial-updates:
sudo apt install virtualbox=5.0.32-dfsg-0ubuntu1.16.04.2

And after all, check that the correct version is installed.
From command line:
dpkg -l virtualbox* | grep ^i

ii  virtualbox                     5.0.32-dfsg-0ubuntu1.16.04.2 amd64        x86 virtualization solution - base binaries
ii  virtualbox-dkms                5.0.32-dfsg-0ubuntu1.16.04.2 all          x86 virtualization solution - kernel module sources for dkms
ii  virtualbox-qt                  5.0.32-dfsg-0ubuntu1.16.04.2 amd64        x86 virtualization solution - Qt based user interface
From GUI: to make sure correct version is running.

Install virtualbox extension pack

sudo /sbin/vboxconfig
sudo apt install virtualbox-ext-pack




For CentOS

1. Display VirtualBox installed
sudo yum update
sudo yum list installed | grep -i VirtualBox


2. Remove VirtualBox-5.1

sudo yum remove VirtualBox-5.1

3. Add Required Yum Repositories
cd /etc/yum.repos.d/
wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo

4. Install Required Packages 
yum install gcc make patch  dkms qt libgomp
yum install kernel-headers kernel-devel fontforge binutils glibc-headers glibc-devel


5. Reboot ans start with newest kernel
reboot


6. Reboot ans start with newest kernel
export KERN_DIR=/usr/src/kernels/`uname -r`


7. Install Oracle VirtualBox and Setup
yum install VirtualBox-5.2



8. List vbox modules (vboxpci, vboxnetadp, vboxnetflt, vboxdrv)
lsmod | grep -i vbox


9. Goto https://www.virtualbox.org/wiki/Downloads and run VirtualBox Extension pack for CentOS

Oracle_VM_VirtualBox_Extension_Pack-5.2.0-118431.vbox-extpack
10. List and add user to vboxusers group
cat /etc/group | grep -i vboxusers
sudo usermod -a -G vboxusers $user_name

11. /var/log/vbox-install.log

Change UUID for VirtualBox



sudo VBoxManage internalcommands sethduuid <file.vdi or file.vmdk>




Refer to:
  1. https://askubuntu.com/questions/900794/virtualbox-rtr3initex-failed-with-rc-1912-rc-1912
  2. https://www.if-not-true-then-false.com/2010/install-virtualbox-with-yum-on-fedora-centos-red-hat-rhel/

2017年10月19日 星期四

Add xrdp port on firewalld (CentOs)




1. Check xrdp process

sudo ps aux | grep xrdp

2. Check xrdp service (default port 3389)
sudo netstat -ntlp | grep -i xrdp

3. Edit /usr/lib/firewalld/services/xrdp.xml for Remote Desktop (add port 3389)
    PS: xrdp.xml will add a "xrdp" item on firewalld GUI
<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>xrdp</short>
  <description>This option allows you to access Remote Desktop.</description>
  <port protocol="udp" port="3389"/>
  <port protocol="tcp" port="3389"/>
</service>


4. Start xrdp
sudo systemctl start xrdp.service
sudo systemctl status xrdp.service

5. Add xrdp service for firewalld and reload firewalld
sudo firewall-cmd --permanent --add-service=xrdp
sudo firewall-cmd --reload
sudo systemctl status firewalld



6. Config SELinux
sudo chcon --type=bin_t /usr/sbin/xrdp
sudo chcon --type=bin_t /usr/sbin/xrdp-sesman

7. Check xrdp service (default port 3389) again


sudo netstat -ntlp | grep -i xrdp

Refer to:
  1. http://www.itzgeek.com/how-tos/linux/centos-how-tos/install-xrdp-on-centos-7-rhel-7.html


2017年10月16日 星期一

How to Start / Stop / Enable / Disable firewalld on CentOS 7



Status of firewalld
sudo systemctl status firewalld

Stop firewalld
sudo systemctl stop firewalld


Start firewalld
sudo systemctl start firewalld


Disable firewalld
sudo systemctl disable firewalld

Enable firewalld
sudo systemctl enable firewalld

Unmask firewalld if you got "Failed to start firewalld.service: Unit is masked."
sudo systemctl unmask firewalld

Edit /usr/lib/firewalld/services/svnserve.xml for subversion (add port 3690)
<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>svnserve</short>
  <description>This option allows you to access subversion (svn, svnserve).</description>
  <port protocol="udp" port="3690"/>
  <port protocol="tcp" port="3690"/>
</service>





Refer to
  1. http://blog.xuite.net/tolarku/blog/363801991-CentOS+7+Firewalld+%E9%98%B2%E7%81%AB%E7%89%86%E8%AA%AA%E6%98%8E%E4%BB%8B%E7%B4%B9
  2. https://www.rootusers.com/how-to-open-a-port-in-centos-7-with-firewalld/
  3. https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-using-firewalld-on-centos-7



How To Install Subversion 1.9.x On CentOS 7



Create yum repository (/etc/yum.repos.d/wandisco-svn.repo)
[WandiscoSVN]
name=Wandisco SVN 
baseurl=http://opensource.wandisco.com/centos/7/svn-1.9/RPMS/$basearch/
enabled=1
gpgcheck=0
Remove previous version to avoid conflict
sudo yum remove subversion

sudo yum clean all



Installing subversion
sudo yum install mod_dav_svn subversion

checking svnserve version
svnserve --version
  or
svn --version



Creating Respository
1. make a directory for repositories

sudo mkdir /srv/svn/repos 
cd /srv/svn/repos 
sudo svnadmin create TEST0001V0



Set file permission
sudo chown -R root:svngrp /srv/svn/repos

sudo chmod -R g+rws /srv/svn/repos



2. Modified configuration files
    2.1 TEST0001V0/conf/authz
[groups]

rd2     = tony
[/]

tony    = rw

@rd2    = rw

* =

[repository:/]

@test   = r

* =
 2.2 TEST0001V0/conf/passwd
[users]

tony    = tonypassword

test    = testpassword



2.3 TEST0001V0/conf/svnserve.conf
[general]

anon-access = none

auth-access = write



password-db = passwd

check svn process (looking for svnserve)
sudo ps aux | grep svn

check svn service (default port 3690)
sudo netstat -ntlp | grep -i svn


stop svn server
sudo killall -9 svnserve

start svn server
sudo svnserve -d

How to start svnserve with systemctl systemd

1. /etc/systemd/system/svnserve.service

[Unit]
Description=Subversion protocol daemon
After=syslog.target network.target

[Service]
Type=forking
RuntimeDirectory=svnserve
#PIDFile=/run/svnserve/svnserve.pid
EnvironmentFile=/etc/default/svnserve
#ExecStart=/usr/bin/svnserve $DAEMON_ARGS
#ExecStart=/usr/bin/svnserve -d -r /srv/svn/repos
ExecStart=/usr/bin/svnserve -d
User=svnuser
Group=svngrp
KillMode=control-group
Restart=on-failure

[Install]
WantedBy=multi-user.target
#Alias=svnserve.service

2. /etc/default/svnserve

# svnserve options
DAEMON_ARGS="--daemon --pid-file /run/svnserve/svnserve.pid --root /srv/svn/repos --log-file /var/log/svnserve/svnserve.log"
3. log file
mkdir /var/log/svnserve

chown someone /var/log/svnserve


4. To end with log rotation configuration /etc/logrotate.d/svnserve

/var/log/svnserve/*.log {
    daily
    missingok
    rotate 14
    compress
    notifempty
    create 640 svn adm
    sharedscripts
    postrotate
            if /bin/systemctl status svnserve > /dev/null ; then \
                /bin/systemctl restart svnserve > /dev/null; \
            fi;
    endscript
}

5. Edit /usr/lib/firewalld/services/svnserve.xml for subversion (add port 3690)
    PS: svnserve.xml will add a "svnserve" item on firewalld GUI
<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>svnserve</short>
  <description>This option allows you to access subversion (svn, svnserve).</description>
  <port protocol="udp" port="3690"/>
  <port protocol="tcp" port="3690"/>
</service>


6. Add svnserve service for firewalld and reload firewalld

sudo firewall-cmd --permanent --add-service=svnserve
sudo firewall-cmd --reload
sudo systemctl status firewalld



7. Stop and start svn again
stop svn server
sudo killall -9 svnserve

start svn server
sudo svnserve -d


8. check svn service (default port 3690) again
sudo netstat -ntlp | grep -i svn




Refer to:
  1. https://stackoverflow.com/questions/38197727/how-to-start-svnserve-with-systemctl-systemd/40584047
  2. http://www.voidcn.com/article/p-kwmdzbek-bbu.html
  3. https://www.vultr.com/docs/how-to-setup-an-apache-subversion-svn-server-on-centos-7