Tuesday, June 30, 2015

FTP or SFTP without password in Linux

I want to make shell script to download the file automatically from the linux server. so i want to know, how to pass the username and password parameters in sftp command inside the shell script ?

FTP/SFTP without password

1. If you use sftp:
ssh-keygen
<no passphrase>
ssh-copy-id your_login@remote.host
Now you can log in without password and use simple command in your script: sftp your_login@remote.host

2. If you use ftp:
touch ~/.netrc
echo "machine <remote_host> login <your_login> password <your_password>" > ~/.netrc
chmod 600 ~/.netrc
Now you can login in without password - ftp remote.host

Saturday, June 27, 2015

Fedora 21 bluetooth not able send/receive file

In Fedora 21, Bluetooth will not send/receive file by default. It will just act as a bluetooth speaker. To send/receive file in Fedora, you need to install Bluetooth Manager package. There are several Bluetooth manager package but I opt for Blueman.

Installing Bluetooth Manager:

To install bluetooth manager package you can run the below command as root or sudo-user.

yum install blueman

After installing this package search in apps for Bluetooth Manager. Then pair your devices. From the Bluetooth manager window you can send files.

Turn on Bluetooth service

Before using the Bluetooth manger you need to start the bluetooth service as root. If you don't start the service, the bluetooth manger may not work as you expect. To turn on the bluetooth service give below command as root.

service bluetooth restart

Tuesday, June 23, 2015

Tools to get mail alert notification if disk space is full Linux

Is there any tools to get mail alert notification if disk space is full?

 Tools

You can use Nagios tool and set disk alert as per your requirement. Nagios is a centralised monitoring service. If you need that only for 1 server you don't need nagios.
 

A single script could help you or use munin or monit toolsI guess it could help you too. So, below tools can be used.

  • Nagios
  • Munin
  • Monit

 Script to monitor

Of course you need to configure your server to allow mail sending.

#!/bin/bash
a=`df -h | sed '1d' | awk '$5 > 30 {print $5}' | tr -d %`
if [[ $a -ge 95 ]]

then
echo "running out of disk space"
mail -s "diskalert: $a%"
yourmail@address.com
fi


OR

#! /bin/bash
mail='yourmail@address.com'
reg='^[0-9]+$'
result=`df|awk '{print $1,$5}'|tail -n+2|tr -d '%'`

for i in $result; do
if [[ $i =~ $reg ]]; then
[[ $i -gt 90 ]] && (echo $result|mail -s "Disk alert" $mail ) && break
fi
done


Monday, June 22, 2015

What does a dot in file permissions signify - Linux?

What does a dot in file permissions signify? As in rwx rwx rwx.

Following the file mode bits (rwx) is a single character that specifies whether an alternate access method such as an access control list applies to the file. When the character following the file mode bits is a space, there is no alternate access method. When it is a printing character, then there is such a method. 

GNU ‘ls’ uses a ‘.’ character to indicate a file with a security context, but no other alternate access method. 

A file with any other combination of alternate access methods is marked with a ‘+’ character.

Tuesday, June 16, 2015

How to create multiple user at the time in only one command?

Simple command or script to to create multiple user at the time.

[root@localhost]# newusers

(# newusers /root/batch-user-add.txt ) you can use this command for creating a number of users at a time. try it once and check the status.

Try this :- for man info
[root@localhost]# man newusers


Linux newusers Command — Creating bulk users

Sometimes you may want to to create multiple users at the same time. Using the normal methods for bulk user creation can be very tedious and time consuming. Fortunately, Linux offers a way to upload users using new users command. This can also be executed in batch mode as it cannot ask any input.

# newusers FILENAME

This file format is same as the password file.

loginname:password:uid:gid:comment:home_dir:shell


Shell script logic: 

You can use a for loop:

for i in frank alex chandler teja
do
useradd $i
done





OR

for i in `cat users.txt`
do
useradd $i
done

Wednesday, June 10, 2015

astu command in Linux

ASTU is a fictional command used in Mr.Robot TV series. He use this command to restore the hacked server. The command used in Mr.Robot TV series while fixing server are

At 30:20 minute in Mr.Robot TV series.

eterm##$ locate server WBKUW300PS345672
eterm##$ ps aux | grep root
eterm##$ ps aux | grep root | cpuset
eterm##$ astu trace -pid 344 -cmd
eterm##$ astu -ls ./root/fsociety/ -a
eterm##$ fsociety00.dat

Above commands were used by Elliot to restore the server. Among all the above commands, only ps and locate is a real Unix command. PS command is used to list the running process. According to the series, there was a rootkill running in the server. He use ps command to find out the list of running process under root user. He finds out fsociety00.dat is process that made the downtime of server.

Locate command is used to search file in your filesystem. It searches for files only in the path located in /var/lib/mlocate/mlocate.db database file.

Tamil font for Fedora

Tamil font for Fedora can be downloaded using simple yum command. The name of the tamil font is Lohit. Without this font, Tamil font were scrambled like below image:

Dinamalar Website: Before installing Font
After installing the font, the font was clear.
Dinamalar website: After installing Font
The font was not good before installing Lohit.

How to install?

Open Terminal & switch to Root user. Then give the below command. 

yum install lohit-tamil-fonts

Terminal output:

Below is the terminal contents that I did while installing the font. 

[venkat@localhost ~]$ su
Password: 
[root@localhost venkat]# yum install lohit-tamil-fonts
Loaded plugins: langpacks
dvratil-plasma-5                                            | 3.0 kB  00:00     
fedora/21/x86_64/metalink                                   | 4.5 kB  00:00     
google-chrome                                               |  951 B  00:00     
intellinuxgraphics                                          |  951 B  00:00     
rpmfusion-free                                              | 2.5 kB  00:00     
rpmfusion-free-updates                                      | 2.7 kB  00:00     
rpmfusion-nonfree                                           | 1.2 kB  00:00     
rpmfusion-nonfree-updates                                   | 2.7 kB  00:00     
updates/21/x86_64/metalink                                  | 4.5 kB  00:00     
updates                                                     | 4.9 kB  00:00     
updates/21/x86_64/primary_db   FAILED                                          
http://ftp.neowiz.com/fedora/updates/21/x86_64/repodata/c0273bd2855eea5cce190a9621adc3162321068d74570c7574e0780b574f26e7-primary.sqlite.xz: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
(1/3): updates/21/x86_64/group_gz                           | 230 kB  00:01     
(2/3): dvratil-plasma-5/21/x86_64/primary_db                | 225 kB  00:02     
(3/3): updates/21/x86_64/primary_db                         | 8.0 MB  00:14     
(1/5): google-chrome/primary                                | 1.9 kB  00:00     
(2/5): rpmfusion-nonfree-updates/21/x86_64/primary_db       | 127 kB  00:00     
(3/5): updates/21/x86_64/updateinfo                         | 1.2 MB  00:01     
(4/5): rpmfusion-free-updates/21/x86_64/primary_db          | 323 kB  00:01     
(5/5): updates/21/x86_64/pkgtags                            | 1.5 MB  00:05     
google-chrome                                                               3/3
Resolving Dependencies
--> Running transaction check
---> Package lohit-tamil-fonts.noarch 0:2.91.0-2.fc21 will be updated
---> Package lohit-tamil-fonts.noarch 0:2.91.1-1.fc21 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                 Arch         Version               Repository     Size
================================================================================
Updating:
 lohit-tamil-fonts       noarch       2.91.1-1.fc21         updates        38 k

Transaction Summary
================================================================================
Upgrade  1 Package

Total download size: 38 k
Is this ok [y/d/N]: y
Downloading packages:
Not downloading deltainfo for updates, MD is 1.9 M and rpms are 38 k
lohit-tamil-fonts-2.91.1-1.fc21.noarch.rpm                  |  38 kB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction (shutdown inhibited)
  Updating   : lohit-tamil-fonts-2.91.1-1.fc21.noarch                       1/2 
  Cleanup    : lohit-tamil-fonts-2.91.0-2.fc21.noarch                       2/2 
  Verifying  : lohit-tamil-fonts-2.91.1-1.fc21.noarch                       1/2 
  Verifying  : lohit-tamil-fonts-2.91.0-2.fc21.noarch                       2/2 

Updated:
  lohit-tamil-fonts.noarch 0:2.91.1-1.fc21                                      

Complete!

Tuesday, June 9, 2015

Enable or Disable user access Linux

In Linux one user (for ex.. user named p1) is in disable mode. How to enable the user? What is the procedure?

To enable user, we should set the user to shells other than /sbin/nologin you can check available shells in file cat /etc/shells

we have changed the user shell p1 to /bin/sh. user is able to login now


usermod -s /sbin/nologin p1

[root@host-7-57 ~]# usermod -s /bin/sh p1
[root@host-7-57 ~]# su p1
sh-4.2$ bash


Disable a user

If you want user to disable . we can set the user shell to /sbin/nologin

[root@host-7-57 ~]# usermod -s /sbin/nologin p1
[root@host-7-57 ~]# su p1
This account is currently not available.-----> no allowing user to login

 
[root@host-7-57 ~]# getent passwd p1
p1:x:500:500::/home/p1:/sbin/nologin


Unlock a user 

Sometimes if user enter wrong password for 5 times, the account gets locked. You can enable it by following command.

[root@localhost ~]# passwd -u p1
Unlocking password for user p1.
passwd: Success

Tuesday, June 2, 2015

Hardlink and softlik difference with examples

when we create softlink the permission is different from source file while when we create hard link the permission is same as source file , why it is so ?

Below is examples of softlink and hardlink

Hardlink

[root@host-7-25 ~]# cd p2
[root@host-7-25 p2]# pwd
/root/p2
[root@host-7-25 p2]# ls -ltr
total 4
-rw-r--r--. 1 root root 0 May 18 08:59 2
-rw-r--r--. 2 root root 84 May 18 09:01 1

[root@host-7-25 p2]# ls
1 2
[root@host-7-25 p2]# ln /root/p2/1 /var/hardlink1------> command used to create hardlink

hardlink has been created

[root@host-7-25 p2]# ls -li /var/hardlink1
519 -rw-r--r--. 2 root root 84 May 18 09:01 /var/hardlink1--------> harlinked file

root@host-7-25 p2]# ls -li 1
519 -rw-r--r--. 2 root root 0 May 18 08:59 1-----------> source file

Both hardlink and source file will be having same size and same inode. even source file got deleted you will be able to access the harlinked file.

But this is not case in softlinked file. in softlink if source file is deleted you will not be able to access the soflinked file.

Below is explaination of softlinked file

[root@host-7-25 p2]# ln -s /root/p2/1 /var/softlink1---------->command used to create softlink
[root@host-7-25 p2]# ls -li /var/softlink1
459 lrwxrwxrwx. 1 root root 10 May 18 09:02 /var/softlink1 -> /root/p2/1--------> soft linked file

root@host-7-25 p2]# ls -li 1
519 -rw-r--r--. 2 root root 0 May 18 08:59 1-----------> source file

source and softlinked file inode number will be different softlinked file will be less size when compared to source file. u can access softlinked file only if source file is present. if source file is delted you will not be able to access softlinked file

Its nothing but shortcut in windows


what about different permission of soft link and source file? 

If you change the permission of harlinked file . source file permission will also change and viceversa below is example . hardlink is nothing but linking same source file to another path as backup with same size and inoder

root@host-7-57 p2]# pwd

/root/p2
[root@host-7-57 p2]# ls -ltr 1
-rwxr--r--. 2 root root 84 May 18 09:01 1---------> source file

[root@host-7-57 p2]# ls -ltr /var/hardlink1
-rwxr--r--. 2 root root 84 May 18 09:01 /var/hardlink1-----------------> hardlinked file

[root@host-7-57 p2]# chmod 555 1------> permission applied on source
[root@host-7-57 p2]# ls -ltr 1
-r-xr-xr-x. 2 root root 84 May 18 09:01 1------> source file after permission change
[root@host-7-57 p2]# ls -ltr /var/hardlink1
-r-xr-xr-x. 2 root root 84 May 18 09:01 /var/hardlink1-------------> hardlinked file will also having same permission

In soflink file you cant change the permission ---- in permission sector u can see the letter l it specifies its softlink . all soflinked file will be having same permission lrwxrwxrwx.

we can use softlink only if source file exist . But this not the case in hardlink

[root@host-7-57 p2]# ls -ltr /var/softlink1
lrwxrwxrwx. 1 root root 10 May 18 09:02 /var/softlink1 -> /root/p2/1
[root@host-7-57 p2]#

[root@host-7-57 p2]# chmod 555 /var/softlink1------------> permission apllied
[root@host-7-57 p2]# ls -ltr /var/softlink1
lrwxrwxrwx. 1 root root 10 May 18 09:02 /var/softlink1 -> /root/p2/1-------------> no change after permission apllied
[root@host-7-57 p2]#