‘m a new to CentOS Linux user. How do I create a file from bash prompt without using GUI tools?
I just need a help to show me how to setup java path on Linux. How can I set JAVA_HOME and PATH variables for every user under my Linux system?
Q. Iâ€™m using OpenBSD as VPS os (guest os) under VMWARE server. However OpenBSD pauses for a few seconds to give me a chance to provide parameters to the kernel at boot> prompt. I’d like to force boot loader to wait for 30 seconds instead of default timeout. How do I setup bootloader timeout?
A. OpenBSD uses boot program. The main purpose of this program is to load the system kernel while dealing with the downfalls of the PC BIOS architecture. This program acts as an enhanced boot monitor for PC systems, pro viding a common interface for the kernel to start from. By default, boot attempts to load the kernel executable /bsd. If it fails to find the kernel and no alternative kernel image has been specified, the system will be unable to boot.
/etc/boot.conf file and timeout parameter
/etc/boot.conf is configuration file for bootloader. Open file using text editor:
$ sudo vi /etc/boot.conf
Append / modify timeout parameter as follows:
set timeout 30
Save and close the file. Above line set the 30 second pause at boot-time.
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 protected]:/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 [email protected]:/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 protected]:.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 [email protected]:/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 [email protected] 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.