Q. How do I make remote backups under Linux? Iâ€™ve CentOS 5 Linux server located in remote data center and Iâ€™d like to backup it to local or another server?
A. Both Linux / UNIX come with handy tools to make secure remote backups. You can use tool called rsync for automating remote backups of your Linux, UNIX, Windows server, Mac OS X and BSD systems. rsync is a program with many more options and uses the rsync remote-update protocol to greatly speed up file transfers when the destination file is being updated.
Task: Copy files / backup files from remote Linux server
Let us say you would like to backup files from remote server called server.nixcraft.in and directory called /home/vivek to local directory called /backup, type the command as follows on local system:
$ rsync -avz -e ssh email@example.com:/home/vivek/ /backup
You need to supply password for vivek user.
Task: Exclude files from backup
You can also skip few files from backup. Let us say you don’t want to backup all C source code file, enter:
$ rsync --exclude '*.cpp' -avz -e ssh firstname.lastname@example.org:/home/vivek/ /backup
Task: Automatic backup using a shell script
SSH always prompts for a password. To automate process via a shell script you need to remove password using SSH key i.e. generate passphraseless keys, enter (type at local system):
$ ssh-keygen -t dsa
When asked for to enter passphrase, just press [ENTER] key twice. Now copy public key to remote server:
$ scp ~/.ssh/id_dsa.pub email@example.com:.ssh/authorized_keys
Now you can login without a password. For more information see – howto setup SSH with DSA public key authentication and RSA key authentication for password less login.
Now create a simple shell script as follows:
$ vi backup.sh
rsync --exclude '*.cpp' --exclude '*.log' -avz -e ssh firstname.lastname@example.org:/home/vivek/ /backup
Setup executable permission using chmod command:
$ chmod +x backup.sh
Use cron to command to backup remote server:
$ crontab -e
Make a backup everyday:
Save and close the file.
Q. Iâ€™m using BASH shell filename tab completion feature to complete file names and other stuff. However default tab-completion in bash case-sensitive. It cannot show me /tmp/Y* or /tmp/Y* files. How do I force filename tab-completion in bash case insensitive?
A. According to bash man page completion-ignore-case set to Off. If set to On, readline performs filename matching and completion in a case-insensitive fashion. Readline has variables that can be used to further customize its behavior. A variable may be set in the /etc/inputrc file with a statement of the form. So all you have to do is type following command:
$ set completion-ignore-case on
You need to add set completion-ignore-case on to /etc/inputrc command:
Append text as follows:
set completion-ignore-case on
Close and save the file. For more information read bash man page.
Q. How do I block access to root user over ssh session?
A.. sshd (OpenSSH Daemon) is the daemon program for ssh. Server side ssh configuration is defined in /etc/ssh/sshd_config file.
You need to use DenyUsers option to block access to root user.
This option can be followed by a list of user name patterns, separated by spaces. Login is disallowed for user names that match one of the patterns. Only user names are valid; a numerical user ID is not recognized. By default, login is allowed for all users. If the pattern takes the form USER@HOST then USER and HOST are separately checked, restricting logins to particular users from particular hosts.
Open /etc/ssh/sshd_config file
Use vi command:
# vi /etc/ssh/sshd_config
Deny root user access
Append or modify as follows to block root user:
If you want to block additional user just append names to DenyUsers
DenyUsers root, user2, user3
Save and close the file. Restart sshd service:
Q. How can I configure or change the Virtual Console login to display a pre-login message?
A. The file /etc/issue is a text file which contains a message or system identification to be printed before the login prompt. It may contain various @char and \char sequences, if supported by getty.
Just open file /etc/issue and change the text as per your requirements.
Procedure to change /etc/issue – pre login file
Login as the root user. Open a file
# vi /etc/issue
Append new text as follows:
Welcome to nixCraft Labs!
Today is \d \t @ \n
Save and close the file. \d, \t or \n will expand as follows on run time.
/etc/issue – escape code
The issue-file (/etc/issue or the file set with the -f option) may contain certain escape codes to display the system name, date and time etc. All escape codes consist of a backslash (\) immediately followed by one of the letters explained below.
- \b : Insert the baudrate of the current line.
- \d : Insert the current date.
- \s : Insert the system name, the name of the operating system.
- \l : Insert the name of the current tty line.
- \m : Insert the architecture identifier of the machine, eg. i486
- \n : Insert the nodename of the machine, also known as the hostname.
- \o : Insert the domainname of the machine.
- \r : Insert the release number of the OS, eg. 1.1.9.
- \t : Insert the current time.
- \u : Insert the number of current users logged in.
- \U : Insert the string “1 user” or “ users” where is the number of current users logged in.
- \v : Insert the version of the OS, eg. the build-date etc.
ow do I format Linux file system? Can you tell me command names to format and create a Linux file system? [click to continue…]
Under Linux, you use term called modules for device drivers. The driver can be loaded or unloaded as per your requirement using commands. Each driver or module gives the Linux information on how to control that particular Ethernet card. The name of each module (driver) is listed in the /etc/modules.conf file.
Command to find out Ethernet card driver name
You can try any one of the following command to find out your Ethernet card driver:
# dmesg | grep 'Ethernet driver'
8139cp: 10/100 PCI Ethernet driver v1.2 (Mar 22, 2004)
Or search a file called /var/log/dmesg:
# grep 'Ethernet driver' /var/log/dmesg
8139too Fast Ethernet driver 0.9.27
8139cp: 10/100 PCI Ethernet driver v1.2 (Mar 22, 2004)
You can also get driver name from config file:
# grep eth0 /etc/modules.conf
alias eth0 8139too
# vi /etc/modules.conf
Search for eth0 string.
In above example 8139too is driver loaded for eth0. You can find out more information about this driver using modinfo command:
# modinfo 8139too
modinfo program to show information about a Linux Kernel module. You can also find out all loaded modules or drivers using lsmod command:
# lsmod | less
lsmod is a program to show the status of modules in the Linux Kernel.
Q. How do I use ssh client program in a shell script under UNIX or Linux operating system?
[click to continue…]