Sharing a Folder among Two FTP users

This might be a very simple article for many people but for some it holds the key for a very good & stable solution.

Scenario:
Two users who want to share a folder and upload data. “User A” and “User B”. They are both restricted to their home directories when they connect with FTP. The folder is actually a shared storage where both the users will upload data. Shared storage is mounted under /Bigdata.

Solution:

Create a Directory in home directory of both the users and call it “OurData”

# cd /home/user-A
# mkdir OurData

Now mount the directory with bind option
#mount –bind OurData/ /BigData/

Make it permanent in fstab

vim /etc/fstab

/BigData /home/user-A/OurData none bind 0 0

Repeat the same for User-B

Make sure the following:
1) Make Both users member of same group , lets call it data
2)Give proper permissions to BigData folder  such as 770
3) Setup acl with setfacl for both users.

Now they can connect with FTP and share the data without any issues.

Thanks,
Salman A. Francis
ITpings.com
www.YouTube/Linuxking
Facebook.com/Linuxking77

ACL in Linux

This is a quick howto setup acl on Linux.

Sometimes we run into issue when we only wish to give certain user certain sets of permission and deny the rest. Simple rwx permission are not suffice in such situation therefore we use acls.

Setup ACL:
setfacl -R -m u:salman:rwx secret/
The above will set acl on directroy secret for user salman with read, write and execute permission recursively.

To View ACL:
getface secret
# file: secret/
# owner: apache
# group: apache
user::rwx
user:salman:rwx
group::rwx
mask::rwx
other::r-x
So we can clearly see that although the owner is apache, user salman have full permissions as well.

Thanks for Reading.
Join our FaceBook Group LHZProject “Linux Zero To Hero”
YouTube: www.youtube.com/linuxking

SSH Issue with Cisco Switch

So Today i wanted to login to my old Cisco Switch 2960 from my Suse Linux when i received the following error:

ERROR:
Unable to negotiate with 10.1.1.1 port 22: no matching key exchange method found. Their offer: diffie-helman-group1-sha1
Note**: 10.1.1.1 is ip of my switch with username salman

SOLUTION:
1) Make sure you configure ssh keys with 1024 bits when setting it up in the switch
2) From your Linux machine issue the following command:

# ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 salman@10.1.1.1

Tip**: For Debugging SSH,  use ssh -vvv option.

Thanks for Reading

Join our FB Linux Group LZH
https://www.facebook.com/groups/LZHProject
Subscribe to our YouTube Channel
https://youtube.com/linuxking

Encrypt/Decrypt File with Vim Editor

In this howto we will see how to encrypt and decrypt a file with Vim editor.

Lets Encrypt a file:

linux-06ac:/opt # vim -x encryptedfile.txt
Warning: Using a weak encryption method; see :help 'cm'
Press ENTER or type command to continue

Now Press enter and it will ask you to set a password.

Enter encryption key: **********
Enter same key again: **********

Once you setup the password, you will be presented with the blank page where  you can start writing to the file as you do with Vim.

I am writing ” Helo Linux World” as an example to my encryptedfile.txt , save and quit with :wq

Not cat the file

linux-06ac:/opt # cat encryptedfile.txt 
VimCrypt~01!q"[�HY�&!���+B]3linux-06ac:/opt #

We can see that the file is Encrypted.

 

Decrypt the File:

To Decrypt permanently, open the file as following:

linux-06ac:/opt # vim encryptedfile.txt

Give the password to the file , you set while encrypting it.

Then type :X and press enter twice (without typing anything) when asked for “Enter encryption key:”

Now save and exit with :wq and viola the file is decrypted.

linux-06ac:/opt # cat encryptedfile.txt 
Helo Linux World

Thanks & Regards,

Salman A. Francis

YouTube: YouTube.com/Linuxking
Twitter: linuxking77
Facebook: https://www.facebook.com/groups/LZHProject/

HowTo Mount 8TB USB in CentoS 7 Server.

This howto is about “How To mount 8TB External USB” in CentOs 7 server.

# yum – y install epel-release

# yum -y install ntfs-3g

# lsblk

sdc 8:32 0 7.3T 0 disk
└─sdc1 8:33 0 7.3T

# mount -t ntfs /dev/sdc1 /mnt/

# ls -ltr /mnt

You will see it’s mounted.

Thanks,

Salman A. Francis

YouTube: LinuxKing

Facebook: Linuxking77 – LZHProject

How to Install PhPMyAdmin on Centos 7 from source

Dear Friends,

First of all we will install required repositories.

[root@itpings opt]# yum -y install epel-release
[root@itpings opt]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Now we will install apache, mariadb, mariadb-server and php56

[root@itpings opt]# yum -y install httpd mariadb mariadb-server php56w php56w-mbstring php56w-mysql php56w-soap unzip vim wget

Once installed we will download phpmyadmin from phpmyadmin.net

[root@itpings opt]# wget https://files.phpmyadmin.net/phpMyAdmin/4.7.2/phpMyAdmin-4.7.2-all-languages.zip

unzip the content and move it to /var/www/html and rename the unzipped content to phpmyadmin

[root@itpings html]# unzip phpMyAdmin-4.7.2-all-languages.zip
[root@itpings html]# mv phpMyAdmin-4.7.2-all-languages.zip phpmyadmin

Now Change the ownership of the folder

[root@red html]# chown -R apache.apache phpMyAdmin
[root@red html]# chmod -R 755 phpMyAdmin

Now we will copy config.sample file to config.ini.php

[root@itpings html]# cp config.sample.inc.php config.inc.php

Now we will edit config.inc.php and only add root user and password of mysql ( Make sure you have root user and password of mysql)

/* User used to manipulate with storage */
 $cfg['Servers'][$i]['controlhost'] = '';
// $cfg['Servers'][$i]['controlport'] = '';
 $cfg['Servers'][$i]['controluser'] = 'root';
 $cfg['Servers'][$i]['controlpass'] = 'itpings123';

Now to visit phpmyadmin visit http://<your-ip-address>/phpmyadmin and provide the above user and password.

Done

Thanks,

Salman A. Francis
YouTube: Linuxking
Facebook: LZHProject, Linuxking77

How to Add Physical Disk to Increase Size of /dev/mapper/centos-root

Dear Friends,

I ran into a problem where my openstack machine ran out of space. My Logical FS /dev/mapper/centos-root was only 50GB and most of the space was lost.

Solution:
LVM

I Added a new 500GB HDD (sdb), created partition with parted (sdb1) and gave the below commands:

[root@stack opt]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created

Next Check your Volumes with “vgdisplay” command

[root@stack opt]# vgdisplay 
 --- Volume group ---
 VG Name centos
 System ID 
 Format lvm2
 Metadata Areas 1
 Metadata Sequence No 4
 VG Access read/write
 VG Status resizable
 MAX LV 0
 Cur LV 3
 Open LV 3
 Max PV 0
 Cur PV 1
 Act PV 1
 VG Size 465.27 GiB
 PE Size 4.00 MiB
 Total PE 119109
 Alloc PE / Size 119109 / 465.27 GiB
 Free PE / Size 0 / 0 
 VG UUID TrvUI3-Xt7U-6vzF-5RtW-OfK0-OCOy-Tejrb6
 
 --- Volume group ---
 VG Name cinder-volumes
 System ID 
 Format lvm2
 Metadata Areas 1
 Metadata Sequence No 5
 VG Access read/write
 VG Status resizable
 MAX LV 0
 Cur LV 0
 Open LV 0
 Max PV 0
 Cur PV 1
 Act PV 1
 VG Size 20.60 GiB
 PE Size 4.00 MiB
 Total PE 5273
 Alloc PE / Size 0 / 0 
 Free PE / Size 5273 / 20.60 GiB
 VG UUID 9LDtLm-52Un-1QJA-yc3q-13vE-LqEc-hX0kiU

Continue reading

Convert pkcs12 key to bks format for Android

Dear Reader,

If you ever want to convert a pkcs12 format key to bks format for Android follow the below instructions.

First of all downlaod bcprov-jdk16-1.46.jar file

[root@itpings certs]# wget http://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk16/1.46/bcprov-jdk16-1.46.jar
–2017-06-30 17:05:40– http://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk16/1.46/bcprov-jdk16-1.46.jar
Resolving repo1.maven.org (repo1.maven.org)… 151.101.32.209
Connecting to repo1.maven.org (repo1.maven.org)|151.101.32.209|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 1876535 (1.8M) [application/java-archive]
Saving to: ‘bcprov-jdk16-1.46.jar’

bcprov-jdk16-1.46.j 100%[===================>] 1.79M –.-KB/s in 0.02s

2017-06-30 17:05:40 (89.3 MB/s) – ‘bcprov-jdk16-1.46.jar’ saved [1876535/1876535]

Now Convert the File as follow with keytool

[root@itpings certs]# keytool –importkeystore –srckeystore user.P12 -srcstoretype pkcs12 –destkeystore user.bks –deststoretype bks –provider org.bouncycastle.jce.provider.BouncyCastleProvider -–providerpath bcprov-jdk16-1.46.jar
Enter destination keystore password:
Re-enter new password:
Enter source keystore password:
Entry for alias 1 successfully imported.
Import command completed: 1 entries successfully imported, 0 entries failed or cancelled
[root@itpings certs]# ls
user.bks

Done.

Thanks,
Salman Aftab
ITpings
YouTube: LinuxKing
FaceBook: LZHProject

How to Bring back eth0 on CentOS 7 ( No Dynamic Ethernet Names)

To Install CentOS 7 without dynamic Ethernet names such as enps2001 use the following technique.

Edit the grub file

Go to /etc/default/grub and add the following lines

In front of /root add the following

biosdevname=0 net.ifnames=0

Then issue the following command

grub2-mkconfig -o /boot/grub2/grub.cfg
Reboot the machine and you will see eth0 and eth1 instead of enps2001 etc.

Thanks,
Salman

Linux Tips ( grep the text without hashes and blank lines )

In our second post of linux tips i would like to share a very simple example in which i will use grep tool to remove all the hashes and blank lines from a file.

In our example we will use file1.txt with the following content

linux-11oz:/test # cat file.txt 
#The file with hashes
###
####
##

This is a test file

With lots of spaces


and few lines with


####hashes
###

So lets remove the hashes and blank lines with single grep command

We can use the following trick

linux-11oz:/test # grep . file.txt | grep -v "#"
This is a test file
With lots of spaces
and few lines with

The “.” will remove the blank lines and  “-v” will invert the match of #

Thats how simple it is. If you know a better way of doing it , Please send me an email or comment.

Email: learning@itpings.com

Thanks

Salman A. Francis