Page not found – ShopingServer Wiki https://wiki.shopingserver.com Tutorials and Articles About Technology and Gadgets Wed, 02 Sep 2020 02:24:34 +0000 en-US hourly 1 https://wordpress.org/?v=5.5.14 https://wiki.shopingserver.com/wp-content/uploads/2018/07/cropped-favicon-150x150.png Page not found – ShopingServer Wiki https://wiki.shopingserver.com 32 32 Linux: Find Out How Much Disk Space Left On Hard Drive https://wiki.shopingserver.com/linux-find-much-disk-space-left-hard-drive/ https://wiki.shopingserver.com/linux-find-much-disk-space-left-hard-drive/#respond Sat, 06 Jan 2018 10:12:32 +0000 http://wiki.shopingserver.com/?p=18587 I am a desktop support professional with experience working in a corporate call center environment. Recently, I started to admin RHEL based IBM Linux server. How do I determine how much disk space left in my Linux server?

How do I find out how much disk space I have in Linux for each partition?

 

You need to use the df command. It shows the amount of disk space available on the currently mounted file system. df is used to show or find out following information:

Used and available space.

File system mount points.

File system capacity.

The number of inodes available.

Find of whether there is sufficient space to upgrade or install new apps.

Syntax

The basic syntax is as follows:

df

df /path/to/dev

df [options]

df [options] /path/to/dev

Examples

Type the following command:

# df

# df -H

 

Sample outputs:

Fig.01: df command in action

The following example will provide information only for the partition/device that contains the /home directory:

# df /home

# df -h /home

 

To see inode usage instead of block usage, type:

# df -i

# df -i /

# df -ih /

# df -i /dev/md0

 

Sample outputs:

Filesystem            Inodes   IUsed   IFree IUse% Mounted on

/dev/md0             7872512   35813 7836699    1% /

Pass the -T to find out file system type:

# df -T -h

 

Sample outputs:

Filesystem    Type    Size  Used Avail Use% Mounted on

/dev/md0      ext4    119G  1.8G  111G   2% /

tmpfs        tmpfs   1002M     0 1002M   0% /lib/init/rw

udev         tmpfs   1000M  260K 1000M   1% /dev

tmpfs        tmpfs   1002M     0 1002M   0% /dev/shm

/dev/md2      ext4    1.5T  658G  745G  47% /data

/dev/mapper/cryptvg-mybackup

ext3    591G   78G  484G  14% /securebackup

DF COMMAND OPTIONS

From the df(1):

-a, –all             include dummy file systems

-B, –block-size=SIZE  use SIZE-byte blocks

–total           produce a grand total

-h, –human-readable  print sizes in human readable format (e.g., 1K 234M 2G)

-H, –si              likewise, but use powers of 1000 not 1024

-i, –inodes          list inode information instead of block usage

-k                    like –block-size=1K

-l, –local           limit listing to local file systems

–no-sync         do not invoke sync before getting usage info (default)

-P, –portability     use the POSIX output format

–sync            invoke sync before getting usage info

-t, –type=TYPE       limit listing to file systems of type TYPE

-T, –print-type      print file system type

-x, –exclude-type=TYPE   limit listing to file systems not of type TYPE

 

 

]]>
https://wiki.shopingserver.com/linux-find-much-disk-space-left-hard-drive/feed/ 0
How To Find a Directory On Linux Based System https://wiki.shopingserver.com/find-directory-linux-based-system/ https://wiki.shopingserver.com/find-directory-linux-based-system/#respond Sat, 06 Jan 2018 09:47:25 +0000 http://wiki.shopingserver.com/?p=18553 I

just switched from MS-Windows server admin to Debian Linux server admin role. I need to find a directory called project.images. I was also told that the locate command is the simplest and quickest way to find the locations of files and directories on Linux. But, the locate command is not working out for me. How do I find project.images directory using command line options only?

 

You need to use the find command. It is used to locate files on a Linux or Unix like system. The locate command will searches through a prebuilt database of files generated by updatedb.

 

The find command will search live file-system for files that match the search criteria.

Syntax

The find command syntax is:

find /where/to/look/up criteria action

 

OR

find /dir/path/look/up criteria action

 

OR

find /dir/path/look/up -name  dir-name-here

 

OR

find /dir/path/look/up -name  pattern

 

OR

find /dir/path/look/up -name  dir-name-here  -print

 

OR

find /dir/path/look/up -name  dir-name-here

 

OR

find / -name  dir-name-here

 

OR

find / -type d -name  dir-name-here

 

OR

find / -type d -name  dir-name-here  2>/dev/null

Examples

The following example will show all files in the current directory and all subdirectories:

find

find .

find . -print

Finding a directory

To find a directory called apt in / (root) file system, enter:

Alert: When searching / (root) file system, you need to run the find command as root user.

find / -type d -name  apt

Sample outputs:

/var/log/apt

/var/lib/apt

/var/cache/apt

/etc/apt

/etc/logrotate.d/apt

/etc/cron.daily/apt

How to find a directory named Documents on Linux?

Type the following command to search for Documents directory in your $HOME dir:

$ find $HOME -type d -name Documents

 

Sample outputs:

/home/vivek/Documents

Getting a detailed list of files/dirs

Pass the -ls to list current file in ls command output format:

find  / -name  apt  -ls

Sample outputs:

4719035    4 drwxr-xr-x   2 root     root         4096 Aug 22 06:25 /var/log/apt

4718597    4 drwxr-xr-x   5 root     root         4096 Aug  4 13:46 /var/lib/apt

4718601    4 drwxr-xr-x   3 root     root         4096 Aug  8 09:37 /var/cache/apt

917524    4 drwxr-xr-x   6 root     root         4096 Jun 18 02:28 /etc/apt

917721    4 -rw-r–r–   1 root     root          173 Apr 15  2011 /etc/logrotate.d/apt

918762   16 -rwxr-xr-x   1 root     root        14985 Mar 14 12:48 /etc/cron.daily/apt

How do I list only directories?

Just find directories and skip file names pass the -type d option as follows:

find  / -type d -name  apt  -ls

Sample outputs:

4719035    4 drwxr-xr-x   2 root     root         4096 Aug 22 06:25 /var/log/apt

4718597    4 drwxr-xr-x   5 root     root         4096 Aug  4 13:46 /var/lib/apt

4718601    4 drwxr-xr-x   3 root     root         4096 Aug  8 09:37 /var/cache/apt

917524    4 drwxr-xr-x   6 root     root         4096 Jun 18 02:28 /etc/apt

How do I perform a case insensitive search?

Replace -name option with -iname as follows:

find  / -type d -iname  apt  -ls

OR

find  / -type d -iname  apt

The patterns ‘apt’ match the directory names ‘apt’, ‘APT’, ‘Apt’, ‘apT’, etc.

How do I find a directory called project.images?

Type any one of the following command:

find  / -type d -iname  project.images  -ls

OR

find  / -type d -name  project.images  -ls

OR

find  / -type d -name  project.images

It is also possible to use the wild cards as follows:

find  / -type d -name  project.*

find  /dir/to/search/ -type d -name  project.image??

A note about locate command

To search for a file/dir named exactly project.images (not *project.images*), type:

locate -b  \project.images

See also

All find command examples from our /faq/ sections.

find(1)

 

 

]]>
https://wiki.shopingserver.com/find-directory-linux-based-system/feed/ 0
Debian / Ubuntu: Install Duplicity For Encrypted Backup In Cloud https://wiki.shopingserver.com/debian-ubuntu-install-duplicity-encrypted-backup-cloud/ https://wiki.shopingserver.com/debian-ubuntu-install-duplicity-encrypted-backup-cloud/#respond Sat, 06 Jan 2018 09:32:20 +0000 http://wiki.shopingserver.com/?p=18537 My cloud based backup service provider has ssh access to the backup system. How do I install and configure duplicity software for remote backups in incremental and encrypted format on Debian or Ubuntu Linux based desktop / laptop / server?

 

Duplicity is a piece of software which provides easy encrypted versioned remote backup of files requiring little of the remote server. It does this using GnuPG, tar, and rdiff. To transmit data it can use ssh/scp, local file access, rsync, ftp, and Amazon S3.

You also need to setup a passphrase. A passphrase is a sequence of words or other text used to control access to a computer system, program or data.

A passphrase is similar to a password in usage, but is generally longer for added security. Passphrases are often used to control both access to, and operation of, cryptographic programs and systems.

Passphrases are particularly applicable to systems that use the passphrase as an encryption key. I strongly recommend that you setup a passphrase for your ssh-keys.

Install duplicity on Debian / Ubuntu Linux

Open the terminal and type the following command (Red hat and friends see our previous faq “Install duplicity on RHEL/CentOS based systems” for more information):

$ sudo apt-get install duplicity

 

OR

# apt-get install duplicity

 

Sample outputs:

Reading package lists… Done

Building dependency tree

Reading state information… Done

The following extra packages will be installed:

librsync1 python-crypto python-gnupginterface python-paramiko

Suggested packages:

python-boto ncftp python-pexpect python-cloudfiles python-gdata tahoe-lafs

python-crypto-dbg python-crypto-doc

The following NEW packages will be installed:

duplicity librsync1 python-crypto python-gnupginterface python-paramiko

0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.

Need to get 1,735 kB of archives.

After this operation, 10.4 MB of additional disk space will be used.

Do you want to continue [Y/n]? y

Get:1 http://mirrors.kernel.org/debian/ stable/main librsync1 amd64 0.9.7-9 [72.1 kB]

Get:2 http://mirrors.kernel.org/debian/ stable/main python-gnupginterface all 0.3.2-9.1 [21.0 kB]

Get:3 http://mirrors.kernel.org/debian/ stable/main duplicity amd64 0.6.18-3 [309 kB]

Get:4 http://mirrors.kernel.org/debian/ stable/main python-crypto amd64 2.6-4 [524 kB]

Get:5 http://mirrors.kernel.org/debian/ stable/main python-paramiko all 1.7.7.1-3.1 [809 kB]

Fetched 1,735 kB in 6s (262 kB/s)

Selecting previously unselected package librsync1:amd64.

(Reading database … 36532 files and directories currently installed.)

Unpacking librsync1:amd64 (from …/librsync1_0.9.7-9_amd64.deb) …

Selecting previously unselected package python-gnupginterface.

Unpacking python-gnupginterface (from …/python-gnupginterface_0.3.2-9.1_all.deb) …

Selecting previously unselected package duplicity.

Unpacking duplicity (from …/duplicity_0.6.18-3_amd64.deb) …

Selecting previously unselected package python-crypto.

Unpacking python-crypto (from …/python-crypto_2.6-4_amd64.deb) …

Selecting previously unselected package python-paramiko.

Unpacking python-paramiko (from …/python-paramiko_1.7.7.1-3.1_all.deb) …

Processing triggers for man-db …

 

 

 

 

 

 

Processing triggers for python-support …

How do I create SSH keys?

To run automated backups, you must set password-less SSH connections using an SSH keys. Use ssh-keygen command to create ssh-keys:

ssh-keygen -t rsa

Skip a passphrase (not recommend)

If you trust your local system/server/latop/desktop do not enter a passphrase. Just hit enter twice and set an empty passphrase. See the following step-by-step guide for detailed information on setting up ssh keys:

Howto Linux / UNIX setup SSH with DSA public key authentication (password less login)

Howto use multiple SSH keys for password less login?

Setup a passphrase for ssh keys (recommend)

If you are paranoid, set a passphrase when prompted and install keychain to setup password less login:

$ sudo apt-get install keychain

 

Edit your ~/.bash_profile, enter:

vi $HOME/.bash_profile

 

Append the following keychain config directives:

Note –clear option is a security feature ##

/usr/bin/keychain –clear  $HOME/.ssh/id_rsa

source $HOME/.keychain/$HOSTNAME-sh

Save and close the file. See our faq: “keychain: Set Up Secure Passwordless SSH Access For Backup Scripts” for more information.

How do I create a GPG keys?

Install GNU privacy guard – a free PGP replacement:

# apt-get install gnupg

 

OR

$ sudo apt-get install gnupg

 

Type the following command to create a GPG key to encrypt backups:

# gpg –gen-key

 

Sample outputs:

gpg (GnuPG) 1.4.12; Copyright (C) 2012 Free Software Foundation, Inc.

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.

 

gpg: keyring `/root/.gnupg/secring.gpg  created

Please select what kind of key you want:

(1) RSA and RSA (default)

(2) DSA and Elgamal

(3) DSA (sign only)

(4) RSA (sign only)

Your selection? 1

RSA keys may be between 1024 and 4096 bits long.

What keysize do you want? (2048) 4096

Requested keysize is 4096 bits

Please specify how long the key should be valid.

0 = key does not expire

<n>  = key expires in n days

<n>w = key expires in n weeks

<n>m = key expires in n months

<n>y = key expires in n years

Key is valid for? (0) 0

Key does not expire at all

Is this correct? (y/N) y

 

You need a user ID to identify your key; the software constructs the user ID

from the Real Name, Comment and Email Address in this form:

Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>

 

Real name: Home Nas Server

Email address: root@nas01

Comment: Home Nas Server Backup

You selected this USER-ID:

Home Nas Server (Home Nas Server Backup) <root@nas01>

 

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O

You need a Passphrase to protect your secret key.

To list your gpg keys, run:

# gpg –list-keys

 

Sample outputs:

/root/.gnupg/pubring.gpg


pub   4096R/4AABBCC7 2013-10-04

uid                  Home Nas Server (Home Nas Server Backup) <root@nas01>

sub   4096R/12345678 2013-10-04

You need to note down the public key 4AABBCC7.

How do I backup files?

The following example use scp to backup /home/nixcraft/ to ~/backups on the cloud.example.com system:

duplicity /home/nixcraft/ scp://user@cloud.example.com/backups

Exclude the files from backup

The following command will backup the / (whole root file system) but excludes /tmp, /proc, /nas, /jails, and /mnt directories from backup:

duplicity –exclude /tmp/ –exclude /proc/ –exclude /nas/ \

–exclude /jails/ –exclude /mnt/ / scp://user@cloud.example.com/backups

Include the files in backup

The following command will backup only the /home/, /root/, /etc/, and /var/spool/cron/ directories under root (/) file system using the –include option:

duplicity –include /home/ –include /root –include /etc/ \

–include /var/spool/cron/ –exclude  **  / scp://user@cloud.example.com/backups

Encrypted backup commands

When backing up, encrypt to the given public key, instead of using symmetric (traditional) encryption. You need to use the –encrypt-key option as follows. To find out your gpg key-id use the following command:

gpg –list-keys

Full backup duplicity command

To make full encrypted backup, enter:

duplicity full –encrypt-key= 4AABBCC7  /home/nixcraft/ scp://userNameHere@cloud.example.com/backups

Incremental backup duplicity command

To make incremental encrypted backup, enter:

duplicity incr –encrypt-key= 4AABBCC7  /home/nixcraft/ scp://userNameHere@cloud.example.com/backups

List the files stored in the archive

To see the files currently backed up in the archive, enter:

duplicity list-current-files –encrypt-key= 4AABBCC7  scp://userNameHere@cloud.example.com/backups

Verify backup duplicity command

You can verify backup with the following command:

duplicity verify –encrypt-key= 4AABBCC7  scp://userNameHere@cloud.example.com/backups /home/nixcraft

Rotate backup duplicity command

You can delete all backup sets older than the given time. Now suppose you want to retain 60 days of backup and remove files older than 60 days, enter:

duplicity remove-older-than 60D –encrypt-key= 4AABBCC7  –force scp://userNameHere@cloud.example.com/backups

Pass the remove-all-but-n-full count to delete all backups sets that are older than the count:th last full backup. In other words, keep the last count full backups and associated incremental ets). The count must be larger than zero. A value of 1 means that only the single most recent backup chain will be kept. Note that the option –force will be needed to delete the files rather than just list them.

duplicity remove-all-but-n-full 10 –encrypt-key= 4AABBCC7  –force scp://userNameHere@cloud.example.com/backups

Restore (recover) last backup duplicity command

Now suppose you accidentally delete /home/nixcraft/ and want to restore it the way it was at the time of last backup, enter:

mkdir /home/nixcraft/

duplicity –encrypt-key= 4AABBCC7  scp://userNameHere@cloud.example.com/backups /home/nixcraft/

Restore (recover) specific file duplicity command

If you wanted to restore just the file “Documents/resume.doc” in /home/nixcraft/ as it was seven days ago into /home/nixcraft/Documents, type:

duplicity -t 7D –file-to-restore= Documents/resume.doc  –encrypt-key= 4AABBCC7  scp://userNameHere@cloud.example.com/backups /home/nixcraft/Documents

Cleaning up backups

You can delete the extraneous duplicity files. Non-duplicity files, or files in complete data sets will not be deleted. This should only be necessary after a duplicity session fails or is aborted prematurely. Note that the –force option will be needed to delete the files rather than just list them:

duplicity cleanup –force –encrypt-key= 4AABBCC7  scp://userNameHere@cloud.example.com/backups

Putting it all together

A sample shell script:

#!/bin/bash

# A simple backup script wrapper for duplicity.

# Author – nixCraft <www.cyberciti.biz> under GPL v2+

# —————————————————–

 

Define VARS ##

_gpg_key= 4AABBCC7

_target= scp://userNameHere@cloud.example.com/backups

_duplicity= /usr/bin/duplicity

_src= /home/nixcraft/

 

Unlock ssh/scp/sftp ##

source $HOME/.keychain/$HOSTNAME-sh

 

Cleanup ##

$_duplicity –force –encrypt-key= ${_gpg_key}  ${_target}

 

Rotate old backups than 60 days ##

$_duplicity remove-older-than 60D –encrypt-key= ${_gpg_key}  ${_target}

 

Backup our home sweet home i.e. /home/nixcraft/ ##

Note: full backup if older than 60 day else do incremental backup ###

$_duplicity ${_src} –encrypt-key= ${_gpg_key}  –full-if-older-than 60D ${_target}

Setup cron job as follows:

@daily /path/to/your/awesome/backup.script.sh

Recommend readings:

Man pages: ssh(1),scp(1),duplicity(1),cron(8),bash(1)

duplicity home page

 

 

]]>
https://wiki.shopingserver.com/debian-ubuntu-install-duplicity-encrypted-backup-cloud/feed/ 0
Unix / Linux: Check New Files In File System /var/www/uploads/ https://wiki.shopingserver.com/unix-linux-check-new-files-file-system-var-www-uploads/ https://wiki.shopingserver.com/unix-linux-check-new-files-file-system-var-www-uploads/#respond Sat, 06 Jan 2018 08:35:40 +0000 http://wiki.shopingserver.com/?p=18471 R

ecently, I switched from MS-Windows based web-server to CentOS Linux based Apache web-server. All user uploaded files are stored in /var/www/uploads/ directory. Is there command that can give me a list of files that have been added to the filesystem at /var/www/uploads/ in last 7 days on Linux/Unix-like oses?

 

You need to use the following commands:

date command – Get the system date.

touch command – Create a file and set file timestamps using date command.

find command – Search for files in file system as per given condition.

Step #1: Get the current date

Type the following date command to get the date as per your requirements:

get old date i.e. if today is 27/Jan get 20/Jan in $d ##

d=$(date + %Y-%m-%d  –date= 7 days ago )

echo  $d

Sample outputs:

2014-01-20

Step #2: Create a new file

Type the following touch command:

file= /tmp/test.txt.$$

touch –date  $d   $file

echo  $file

ls -l  $file

Sample outputs:

/tmp/test.txt.17697

-rw-r–r–. 1 nixcraft nixcraft 0 Jan 20 00:00 /tmp/test.txt.17697

Step #3: List newer files

To find files in the /var/www/upload/ directory tree that are newer than the $file (/tmp/test.txt.17697 file), use the find command as follows:

find /var/www/upload/ -newer $file

OR

find /var/www/upload/ -type f -newer $file

OR

find /var/www/upload/ -type f -iname  *.jpg  -newer $file

OR

find /var/www/upload/ -iname  *.jpg  -newer $file -ls

OR bsd/unix safe options:

find /var/www/upload/ -name  *.jpg  -newer $file -exec ls -l {} \;

Sample outputs:

15728917   20 -r–r–r–   1 cyberciti cyberciti    18144 Jan 27 06:47 ./01/last-command-output-300×118.jpg

11534726   92 -r–r–r–   1 cyberciti cyberciti    91370 Jan 27 06:47 ./01/last-command-output.jpg

11534720   12 -r–r–r–   1 cyberciti cyberciti     9691 Jan 27 03:44 ./01/who-command.jpg

11534721  104 -r–r–r–   1 cyberciti cyberciti   104077 Jan 27 04:08 ./01/who-command-output.jpg

A shell script to check new files in the file system

#!/bin/bash

# A quick shell script to show new files added to the file system

# Syntax ./script /path/to/dir days

# Defaults ./script $PWD 3

# Author: nixCraft <webmaster@cyberciti.biz> under GPL v2.x+

# —————————————————————–

_pwd= $(pwd)

_now=$(date + %Y-%m-%d  –date= ${2:-3} days ago )

_d= ${1:-$_pwd}

 

# a bad idea but I m too lazy

_f= /tmp/thisfile.$$

 

touch –date  $_now   $_f

find  $_d  -type f -newer  $_f

/bin/rm -f  $_f

Sample outputs:

./script

/home/nixcraft

/home/nixcraft/.viminfo

/home/nixcraft/.lesshst

/home/nixcraft/.bash_history

 

./script 7 /var/www/uploads/

/var/www/uploads/who-command-150×119.jpg

/var/www/uploads/last-command-output-150×150.jpg

/var/www/uploads/who-command-output-150×150.jpg

/var/www/uploads/ubuntu-find-ip-address-ip-command-300×64.png

/var/www/uploads/redhat-rhel-version-release-command.png

find command mtime option

Pass the -mtime n option to find command to get file’s data was last modified n*24 hours ago, so:

List files uploaded in last 3 days directly using find command ###

GNU/Linux specific example ##

find /var/www/uploads/ -iname  *.jpg  -type f -mtime -3 -ls

OR try the following bsd/unix specific example:

list files uploaded in last 3 days directly using find command ###

find . -iname  *.jpg  -type f -mtime -3 -print0 | xargs -I {} -0 ls -l  {}

Recommended readings

Find Files By Access, Modification Date / Time Under Linux or UNIX

Linux incrond inotify: Monitor Directories For Changes And Take Action

Man pages: find(1),date(1),touch(1)

 

 

]]>
https://wiki.shopingserver.com/unix-linux-check-new-files-file-system-var-www-uploads/feed/ 0
Increase NFS Client Mount Point Security For a Web-Server noexec, nosuid, nodev Options https://wiki.shopingserver.com/increase-nfs-client-mount-point-security-web-server-noexec-nosuid-nodev-options/ https://wiki.shopingserver.com/increase-nfs-client-mount-point-security-web-server-noexec-nosuid-nodev-options/#respond Sat, 06 Jan 2018 08:32:55 +0000 http://wiki.shopingserver.com/?p=18467 I

am using NFS server version 4.x on a CentOS/RHEL based system. I’m mounting my shared /var/www/ directory on five Apache based nodes using the following syntax:

mount -t nfs4 -o rw,intr,hard,proto=tcp rocknas02:/httproot/www /var/www/

I noticed that due to bug in my app user can sometime upload executable or other device files to get out of chrooted Apache server. How can I prevent such security issues on a CentOS or RHEL based NFS client and sever setup?

 

First, you need to fix your application. Next, you can pass the following three options to mount command to increase overall security on Apache/Nginx/Lighttpd nfs based client:

noexec – Prevents execution of binaries on mounted file systems. This prevents remote users from executing unwanted binaries on your system.

nosuid – Disables set-user-identifier or set-group-identifier bits. This prevents remote users from gaining higher privileges by running a setuid program.

nodev – Prevents character and block special devices from being defined, or if they exist, from being used as character and block special devices. This prevents remote users from getting out of chrooted server jails.

Modify your mount command as follows:

# mount -t nfs4 -o rw,intr,hard,proto=tcp,nodev,noexec,nosuid rocknas02:/httproot/www /var/www/

 

OR attempt to remount an already-mounted nfsv4.0 filesystem:

# mount -t nfs4 -o remount,rw,intr,hard,proto=tcp,nodev,noexec,nosuid rocknas02:/httproot/www /var/www/

Test it

To verify new settings, enter:

# mount

# mount | grep rocknas02

 

Sample outputs:

rocknas02:/httproot/www on /var/www type nfs4 (rw,noexec,nosuid,nodev,sync,intr,hard,proto=tcp,addr=192.168.1.10,clientaddr=192.168.1.100)

Copy /bin/ls to rocknas02:/httproot/www i.e. type the following on your nfsv4.0 server called rocknas02

# cp /bin/ls /httproot/www

 

On client, type:

cd /var/www

 

run /bin/ls

ls -l

 

# Run uploaded ls

./ls

Sample outputs:

Fig. 01: Running ls command on nfs client

 

Updating /etc/fstab is left as an exercise for the reader.

Mount the filesystem read-only

If possible mount the filesystem in read-only mode. Modify your mount command as follows:

# mount -t nfs4 -o ro,intr,hard,proto=tcp,nodev,noexec,nosuid rocknas02:/httproot/www /var/www/

 

OR attempt to remount an already-mounted nfsv4.0 filesystem:

# mount -t nfs4 -o remount,ro,intr,hard,proto=tcp,nodev,noexec,nosuid rocknas02:/httproot/www /var/www/

Recommend file/directory permission for Apache

I suggest the following schema:

Run Apache as apache user and group

You must run httpd as root initially and it will switch to apache user and group:

# egrep -i  ^(User|Group)  /etc/httpd/conf/httpd.conf

 

Sample outputs:

User apache

Group apache

NFS server file/directory permission for /var/www/

Create a user called www-files using useradd command:

# useradd -d /var/www -M -s /sbin/nologin www-files

 

Make sure you lock www-files account using passwd command:

# passwd -l www-files

 

Change file owner and group to www-files for /var/www directory use the following passwd command:

# chown -R www-files:www-files /var/www/

 

Finally changes the file mode bits of each given file and directory according to mode:

By default all files & dirs permissions are set to read-only ###

chmod -R 0444 /var/www

 

Allow, apache/nginx/lighttpd to serve files from directory by settings others to x bit ###

find /var/www -type d -print0 | xargs -0 -I {} chmod 0445  {}

 

Optional certain directory may need additional permissions such as /var/www/uploads ###

#chmod  0777 -R /var/www/uploads

Use ls -l command to verify file permissions:

# cd /var/www

# ls -l

 

Sample outputs:

total 32

-r–r–r–. 1 www-files www-files  606 Dec 21  2011 best_resources.php

-r–r–r–. 1 www-files www-files 1068 Sep  4  2011 cdn_info_linux_unix_setup.php

dr–r–r-x. 2 www-files www-files 4096 Aug  5  2012 data

….

-r–r–r–. 1 www-files www-files 1550 Jun 22  2012 service-per-vm-guide.php

See also

How to configure php to deny file uploads.

This entry is 15 of 15 in the Linux / UNIX NFS File Server Tutorial series. Keep reading the rest of the series:

CentOS / Redhat: Setup NFS v4.0 File Server

Debian / Ubuntu Linux: Setup NFSv4 File Server

Mac Os X: Mount NFS Share / Set an NFS Client

RHEL: How Do I Start and Stop NFS Service?

How To Restart Linux NFS Server Properly When Network Become Unavailable

Linux Iptables Allow NFS Clients to Access the NFS Server

Debian / Ubuntu Linux Disable / Remove All NFS Services

Linux: Tune NFS Performance

Mount NFS file system over a slow and busy network

Linux Track NFS Directory / Disk I/O Stats

Linux Disable / Remove All NFS Services

Linux: NFS4 mount Error reason given by server: No such file or directory

Linux NFS Mount: wrong fs type, bad option, bad superblock on fs2:/data3 Error And Solution

CentOS / RHEL CacheFS: Speed Up Network File System (NFS) File Access

Increase NFS Client Mount Point Security

 

 

]]>
https://wiki.shopingserver.com/increase-nfs-client-mount-point-security-web-server-noexec-nosuid-nodev-options/feed/ 0
FreeBSD Show Disk Quota Limits Command https://wiki.shopingserver.com/freebsd-show-disk-quota-limits-command/ https://wiki.shopingserver.com/freebsd-show-disk-quota-limits-command/#respond Sat, 06 Jan 2018 08:26:22 +0000 http://wiki.shopingserver.com/?p=18459 I

‘m a new FreeBSD unix user and backup file on a FreeBSD based unix server. How can I check quota limits and disk usage using shell prompt on a FreeBSD based system?

 

You need to use the quota command line utility to see your disk usage and limits. By default only the user quotas are printed. Disk block usage and limits are shown in 1024-byte blocks.

Checking Disk Quota on FreeBSD Server

The syntax is as follows:

quota

quota -v

quota [options] username

quota [options] groupname

The following is sample output from my server:

$ quota -v

 

OR

$ quota -v -h

 

Sample outputs:

Disk quotas for user vivek (uid 40142):

Filesystem   usage    quota   limit   grace  files   quota  limit   grace

/mnt/sales      0B       0B      0B               0         0       0

/mnt/homes   7289M   97656M 107422M             579   10000000 11000000

Where,

-v : Display quotas on file systems where no storage is allocated.

-h : “Human-readable” output. Use unit suffixes: Byte, Kilobyte,Megabyte, Gigabyte, Terabyte and Petabyte.

You can use the following command over ssh based session:

ssh vivek@nas01 quota -hv

ssh vivek@server1.cyberciti.biz quota -hv

I strongly suggest that you read quota man page for more information.

 

 

]]>
https://wiki.shopingserver.com/freebsd-show-disk-quota-limits-command/feed/ 0
Linux/Unix: Find Command Ignore Case Insensitive Search https://wiki.shopingserver.com/linux-unix-find-command-ignore-case-insensitive-search/ https://wiki.shopingserver.com/linux-unix-find-command-ignore-case-insensitive-search/#respond Sat, 06 Jan 2018 08:10:24 +0000 http://wiki.shopingserver.com/?p=18441 I

am a new Linux and Unix-command line user. I am using find command to search file called “fooBar.conf.sample” in my home directory. I do not know the case, it could be uppercase, lowercase, or a mix of both. How can search a file and ignore case on a Linux or Unix-like system?

 

The find command recursively descends the directory tree for each path provided, evaluating an expression. It is mainly used to search files and directories on Linux and Unix-like systems. The syntax is as follows to search files according to given criteria. You can search for files by name, owner, group, type, permissions, date, and other criteria:

find dir-to-look criteria what-to-do

OR

find [options] dir-to-look criteria what-to-do

In this example, search your $HOME for a file called hello.c:

find $HOME -name  hello.c  -print

This will search the whole $HOME (i.e. /home/username/) system for any files named “hello.c” and display their pathnames:

/Users/vivek/Downloads/hello.c

/Users/vivek/hello.c

However, it will not match HELLO.C or HellO.C. To match is case insensitive pass the -iname option as follows:

find $HOME -iname  hello.c  -print

Sample outputs:

/Users/vivek/Downloads/hello.c

/Users/vivek/Downloads/Y/Hello.C

/Users/vivek/Downloads/Z/HELLO.c

/Users/vivek/hello.c

Finally, pass the -type f option to only search for files:

find /dir/to/search -type f -iname  fooBar.conf.sample  -print

find $HOME -type f -iname  fooBar.conf.sample  -print

A note about AIX/HP-UX and other old Unix-like systems

The -iname works either on GNU or BSD (including OS X) version find command. If your version of find command does not supports -iname, try the following syntax using grep command:

find $HOME | grep -i  hello.c

find $HOME -name  *  -print | grep -i  hello.c

OR try

find $HOME -name  [hH][eE][lL][lL][oO].[cC]  -print

Sample outputs:

/Users/vivek/Downloads/Z/HELLO.C

/Users/vivek/Downloads/Z/HEllO.c

/Users/vivek/Downloads/hello.c

/Users/vivek/hello.c

See also

Solaris UNIX Case-Insensitive Find File Search

See all find command examples from our /faq/ sections.

Man pages – find(1),grep(1)

 

 

]]>
https://wiki.shopingserver.com/linux-unix-find-command-ignore-case-insensitive-search/feed/ 0
Ubuntu Linux Create and Add Swap File Tutorial https://wiki.shopingserver.com/ubuntu-linux-create-add-swap-file-tutorial/ https://wiki.shopingserver.com/ubuntu-linux-create-add-swap-file-tutorial/#respond Fri, 05 Jan 2018 16:20:59 +0000 http://wiki.shopingserver.com/?p=18387 I

‘m a new Ubuntu Linux version 14.04 LTS user. I need additional swap space to improve my Ubuntu server performance. How can I add a swap space on Ubuntu Linux 14.04 LTS using command line over the ssh based session?

 

Swap space is nothing but a disk storage used to increase the amount of memory available on the Ubuntu Linux server. In this tutorial, you will learn how to create and use a swap file on an Ubuntu Linux server.

What is a swap file on Ubuntu server or desktop system?

As a sysadmin it is necessary to add more swap space after installation on the server. Swap file allows Ubuntu Linux to use hard disk to increase virtual memory.

Virtual Memory = RAM + Swap space/file

 

Virtual Memory (1GB) = Actual RAM (512MB) + Swap space/file (512MB)

When the Ubuntu server runs low on memory, it swaps a section of RAM (say an idle program like foo) onto the hard disk (swap space) to free up memory for other programs. Then when you need that program (say foo again), kernel swapped out foo program, it changes places with another program in RAM.

Procedure to add a swap file on a Ubuntu Linux

Open the Terminal app or use the ssh client to get into the remote server. Login as a root user using sudo command:

sudo -s

Create a swap file command

Type the following command to create a 2GB swap file on Ubuntu:

# dd if=/dev/zero of=/swapfile bs=1G count=2

 

Sample outputs:

2+0 records in

2+0 records out

2147483648 bytes (2.1 GB) copied, 20.2256 s, 106 MB/s

Verify that file has been created on the server:

# ls -lh /swapfile

 

Sample outputs:

-rw-r–r– 1 root root 2.0G Oct 29 14:07 /swapfile

Creating swap space using fallocate command instead of dd command

Instead of the dd command, you can use the the faster fallocate command to create swap file as follows:

# fallocate -l 1G /swapfile-1

# ls -lh /swapfile-1

 

Sample outputs:

-rw-r–r– 1 root root 1.0G Oct 29 14:11 /swapfile-1

Secure the swap file

Type the following chmod command and chown command to secure and set correct file permission for security reasons:

# chown root:root /swapfile

# chmod 0600 /swapfile

# ls -lh /swapfile

 

Sample outputs:

-rw——- 1 root root 2.0G Oct 29 14:07 /swapfile

A world-readable swap file is a huge local vulnerability. The above commands make sure only root user can read and write to the file.

Turn on the swap file

First, use the mkswap command as follows to enable the swap space on Ubuntu:

# mkswap /swapfile

 

Sample outputs:

Setting up swapspace version 1, size = 2097148 KiB

no label, UUID=10231c61-6e55-4dd3-8324-9e2a892e7137

Finally, activate the swap file, enter:

# swapon /swapfile

Verify new swap file and settings on Ubuntu

Type the following command

# swapon -s

 

Sample outputs:

Filename    Type  Size Used Priority

/dev/sda5                               partition 3998716 704 -1

/swapfile                               file  2097148 0 -2

You can also run the following commands to verify swap file and its usage:

# grep -i –color swap /proc/meminfo

# top

# htop

# atop

How can I disable swapfile on Ubuntu?

You need to use the swapoff command as follows:

# swapoff /swapfile

# swapon -s

Update /etc/fstab file

You need to make sure the swap file enabled when server comes on line after the reboot. Edit /etc/fstab file, enter:

# vi /etc/fstab

 

Append the following line:

/swapfile none            swap    sw              0       0

Save and close the file.

Tuning the swap file i.e. tuning virtual memory

You can tune the following two settings:

swappiness

min_free_kbytes

vfs_cache_pressure

How do I set swappiness on a Ubuntu server?

The syntax is:

# sysctl vm.swappiness=VALUE

# sysctl vm.swappiness=20

 

OR

# echo VALUE > /proc/sys/vm/swappiness

# echo 30 > /proc/sys/vm/swappiness

 

The value in /proc/sys/vm/swappiness file controls how aggressively the kernel will swap memory pages. Higher values increase agressiveness, lower values descrease aggressiveness. The default value is 60. To make changes permanent add the following line to /etc/sysctl.conf:

echo  vm.swappiness=30  >> /etc/sysctl.conf

For database server such as Oracle or MySQL I suggest you set a swappiness value of 10. For more information see the official Linux kernel virtual memory settings page.

See also:

Linux display system hardware status information gathered from /proc filesystem in easy format (includes swap info)

Man pages – mkswap(8),swapon(8),dd(1),free(1),vmstat(1),top(1)

 

 

]]>
https://wiki.shopingserver.com/ubuntu-linux-create-add-swap-file-tutorial/feed/ 0
How To Add Swap on FreeBSD Unix Systems https://wiki.shopingserver.com/add-swap-freebsd-unix-systems/ https://wiki.shopingserver.com/add-swap-freebsd-unix-systems/#respond Fri, 05 Jan 2018 15:58:03 +0000 http://wiki.shopingserver.com/?p=18361 I

need additional swap space to improve my FreeBSD Unix server/desktop performance. How do I add a swap file to FreeBSD system using command line options without creating a new partitions? How do I encrypt swap space on a FreeBSD Unix server for security purpose?

 

A swap is nothing but space or file on a disk that can used as virtual memory. In FreeBSD and Unix-like operating systems, it is common to use a whole partition of a hard disk for swapping. When a FreeBSD based server runs out of memory, the kernel can move sleeping or inactive processes into swap area. A dedicated Swap partition goes a long way to avoid system freeze but if you notice you are running out of RAM or your applications are consuming too much of it then you may want to setup a swapfile. This guide helps you add a swap space on FreeBSD based Unix server.

How do I add swap on FreeBSD version 9 or older?

You will create the swap file by typing the following dd command as the root user:

dd if=/dev/zero of=/root/swap.8G.bin bs=1M count=8192

This should create an 8GB file called swap.8G.bin in /root/. To make sure this worked you can type:

ls -alh  /root/swap.8G.bin

For security reason set the permissions, run:

chmod 0600 /root/swap.8G.bin

ls -alh  /root/swap.8G.bin

Sample outputs:

Fig.01: How to create a swap file on FreeBSD version 9.X and Earlier Commands

How do I activate swap space on the boot time?

To add this to your rc.conf you will type:

echo  swapfile= /root/swap.8G.bin   >> /etc/rc.conf

If you want to see if it is there in your rc.conf you can type:

tail /etc/rc.conf

Reboot the system:

reboot

A NOTE ABOUT ENABLING THE SWAP FILE IMMEDIATELY WITHOUT REBOOTING THE SYSTEM

If you want to apply the swapfile immediately type the following command:

Enable swap space ##

mdconfig -a -t vnode -f /root/swap.8G.bin -u 0

 

Find out configured devices i.e. swap device name ##

mdconfig -l -v

 

Turn it on ##

swapon /dev/md0

Sample outputs:

Fig.02: FreeBSD find out swap device name created/attached with the mdconfig command

 

To see details of your swap information type:

swapinfo -k

swapinfo -k | grep  /root/swap.8G.bin

swapinfo -h

Sample outputs:

Device          1K-blocks     Used    Avail Capacity

/dev/ada0p3       1048540     736K     1.0G     0%

/dev/md0          8388608       0B     8.0G     0%

Total             9437148     736K     9.0G     0%

How to set up swap file on FreeBSD version 10.x or later

First, create the swap file (128M) using dd command:

dd if=/dev/zero of=/root/swap1 bs=1m count=128

Set the proper permissions on the new file for security reason:

chmod 0600 /root/swap1

Edit /etc/fstab, enter:

vi /etc/fstab

Add/append the following line:

md42 will be assigned by system, use any unused device name (run  mdconfig -lv  to get list of attached memory device names) ##

md42 none swap sw,file=/root/swap1 0 0

If you want to see if it is there in your /etc/fstab you can type:

tail /etc/fstab

Now, swap space will be added on system boot time. To add and activate swap space immediately, run:

swapon -aq

To see details of your swap type:

swapinfo -k

Sample session from my FreeBSD10 based server:

Fig.03: How to add a swap file on FreeBSD version 10.x and Later

A note about securing and encrypting swap space on a FreeBSD server

Encrypting swap space can avoid leakage of sensitive information such as passwords and other data in memory.

Procedure to encrypt swap file

Type the following command to create a swap file called /root/en.swap0

# dd if=/dev/random of=/root/en.swap0 bs=1m count=64

# mdconfig -a -t vnode -f /root/en.swap0

# geom eli init md0

 

Sample outputs:

Enter new passphrase:

Reenter new passphrase:

 

Metadata backup can be found in /var/backups/md0.eli and

can be restored with the following command:

 

# geli restore /var/backups/md0.eli md0

Attach md0, enter:

# geom eli attach md0

 

Turn on encrpted swap file:

# swapon /dev/md0.eli

 

Verify newly created swap space:

# swapinfo -k

 

Sample session:

Fig.04: Encrypting swap file on a FreeBSD 10.x server

 

This hack is a little ugly but works. I strongly suggest that you use encrypted swap space as described here.

How can I disable devices and files for paging and swapping on FreeBSD?

Type the following command to disable /dev/md0 swap space:

# swapoff /dev/md0

# swpainfo -k

How can I display swap usage summary on FreeBSD?

Use the top command:

# top

 

Sample outputs (look for Swap in outputs):

last pid:   874;  load averages:  0.47,  0.32,  0.27                                                                                                                                                                                                    up 0+00:34:48  16:52:35

22 processes:  1 running, 21 sleeping

CPU:  0.0% user,  0.0% nice,  0.0% system,  0.0% interrupt,  100% idle

Mem: 14M Active, 13M Inact, 104M Wired, 80M Buf, 1841M Free

Swap: 1216M Total, 1216M Free

 

PID USERNAME    THR PRI NICE   SIZE    RES STATE    TIME    WCPU COMMAND

721 root          1  20    0 25328K  3704K select   0:00   0.00% ntpd

755 root          1  20    0 86084K  6896K select   0:00   0.00% sshd

765 root          1  20    0 23980K  5188K select   0:00   0.00% sendmail

758 root          1  20    0 23492K  3452K pause    0:00   0.00% csh

….

..

You can also use pstat or swapinfo commands:

# pstat -s

 

OR

# swapinfo -k

 

You can also use vmstat/systat commands:

# vmstat

# systat swap

 

See man pages for more info:

$ man vmstat

$ man systat

$ man top

$ man swapinfo

$ man pstat

 

This entry is 2 of 2 in the Linux and UNIX Swap File Management Tutorial series. Keep reading the rest of the series:

Linux Add a Swap File

FreeBSD Add a Swap File

 

 

]]>
https://wiki.shopingserver.com/add-swap-freebsd-unix-systems/feed/ 0
FreeBSD Unix Show Mounted File Systems https://wiki.shopingserver.com/freebsd-unix-show-mounted-file-systems/ https://wiki.shopingserver.com/freebsd-unix-show-mounted-file-systems/#respond Fri, 05 Jan 2018 15:46:17 +0000 http://wiki.shopingserver.com/?p=18347 I

recently switched from MS-Windows server to a FreeBSD Unix server. How can I see list of mounted file systems on a FreeBSD based Unix server using command line options?

 

The command to view mounted files systems, to mount or add any local devices such USB,DVD/CD or remote file systems such asNFS, SAMBA shares or files is the mount command on a FreeBSD operating systems.

How can I list mounted local and remote file systems?

This will list mounted remote and local file systems, run:

$ mount

 

Sample outputs:

/dev/ada0p2 on / (ufs, local, journaled soft-updates)

devfs on /dev (devfs, local, multilabel)

192.168.1.10:/exports/nas01/data on /mnt/nfs (nfs)

The first field displays the special device such as /dev/ada0p2 or remote file system such as 192.168.1.10:/exports/nas01/data mounted on second field. The second field is the mount point for the file system displayed in the first field. Adding the -v flag will add IDs too:

$ mount -v

 

Sample outputs:

/dev/ada0p2 on / (ufs, local, journaled soft-updates, writes: sync 3 async 50, reads: sync 1193 async 10, fsid f64cdd52f9f387e7)

devfs on /dev (devfs, local, multilabel, fsid 00ff007171000000)

192.168.1.10:/exports/nas01/data on /mnt/nfs (nfs, fsid 01ff003a3a000000)

If you want to see only a specific file system you would use the -t flag. For example, only show a ufs based mounted file system, enter:

$ mount -t ufs

 

OR just show a nfs based mounted file system, type:

$ mount -t nfs

 

Sample outputs:

192.168.1.10:/exports/nas01/data on /mnt/nfs (nfs)

/etc/fstab file

The /etc/fstab contains descriptive information about the various file systems. fstab is only read by programs, and not written; it is the duty of the system administrator to properly create and maintain this file. To see this file, type:

more /etc/fstab

less /etc/fstab

column -t /etc/fstab

Sample outputs:

# Device Mountpoint FStype Options Dump Pass#

/dev/ada0p2 /  ufs rw 1 1

/dev/ada0p3 none  swap sw 0 0

md42     none     swap    sw,file=/root/swap1 0 0

More on column -t command

The column command formats its input into multiple columns. It is useful to display mounted file systems in a table format:

mount | column -t

Or try:

( printf  Device Mounted On (FileSystem_info)\n  ; mount ) | column -t

Sample outputs:

Fig.01: Freebsd Unix mount command and column -t to display output in a table format.

df command examples

The df command shows statistics about the amount of free disk space on a FreeBSD system:

df

 

Use 1024 byte (1 Kibibyte) blocks rather than the default. ##

df -k

 

Human-readable outputs ##

df -H

Sample outputs:

Filesystem                          Size    Used   Avail Capacity  Mounted on

/dev/ada0p2                          20G     11G    7.5G    59%    /

devfs                               1.0k    1.0k      0B   100%    /dev

192.168.1.10:/exports/nas01/data    1.6T    297G    1.2T    20%    /mnt/nfs

This quick tutorial was contributed by Wendy Michele. Editing by admin. You can too contribute to nixCraft.

 

 

]]>
https://wiki.shopingserver.com/freebsd-unix-show-mounted-file-systems/feed/ 0