A: As you probably know SELinux is enabled in Enforcing mode by default on RHEL and Fedora systems and while it helps keep your system secure, of course it is not the panacea to all security risks just one the bricks for a better protection, sometimes it can get in the “middle” of normal operations. Read more…
Q: I’m writing a document/code using VI/VIM and I would like to add the current date to the document. How can I accomplish this?
A: Despite the fact of being weird at time, I always loved the VI editor as it gives you the ability to easily manipulate your document/script as you need using handy keyboard shortcuts. There are two ways, I’m aware of, to add the current date to a document that I will show you here.
Both methods use the Linux standard date command to add the current date, to accomplish this exit the editor mode (with ESC key) and type the following command :
Optionally you can achieve the same result, after exiting the editor mode, typying the following :
A sample output is below :
That is it, as you can see the VI editor can save you a lot of time when editing files and code with handy short-cuts, while for full professional documents I prefer LaTeX I deeply love the VI editor for its efficiency.
Hope you will find the article useful.
Incoming search terms:
Q: I need to copy a file, or set of files, from one machine to a remote machine on a given schedule via SSH. How can I accomplish this?
A: This is a pretty common need and pretty handy when you need to copy files over a machine where the backup software is running. The process of configuring is pretty easy and just involves a few steps needed to automate the login between the two machines. So let’s see what we need to do, for the post I will use a simple copy script but you can easily adopt this to anything needed.
If you never did this generate the public/private key pair that will be used to authenticate between the machines, it’s needless to say that you should export and protect the private key, with the following command :
ssh-keygen -t rsa
You will be asked for a key pass phrase, leave this empty just, again, be sure to protect the private key. Now copy the public key to the remote machine with the following command :
scp ~/.ssh/id_rsa.pub remote_host:/some_dir
Now we need to import the public key to the list of authorized hosts on the “remote” machine so just login to the machine via SSH and issue the following command :
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
This will import the public key to the list of authorized keys (machines) into the authorized list of machines/users who can login without a password, to test this you can issue the following command :
You should get immediately the shell prompt without being asked for a password, if you are prompted for a password double check the steps as something went wrong
No back to the original problem, how do I automate the copy of a file/directory via SCP and cron? Simply open up your crontab file and put your script with the desired schedule something like :
scp -r /PATH_TO_FILES/* REMOTE_USER@remote_host:BACKUPS/
There you go, the machine will automatically execute the script at the desired schedule copying your files from machine to machine without asking any password or any manual interaction.
There are, of course, more elegant or “sophisticated” ways of doing this (rsync, puppet, cfengine just to name a few) but for a simple requirement as the above this will work like a charm.
I hope you found the article useful, if so please take some time to retweet it or to leave a comment!
Incoming search terms:
Q: When I try to launch vim to edit a file I get a command not found error. How can I solve this?
A: You need to manually install VIM on a system running CentOS.
Vim, or VI enhanced, is the successor of the famous vi editor which is found almost in every Linux distribution even on a recovery environment and has some nice features like syntax highlight for files and other useful stuff.
To install it and use in CentOS all you have to do is input the following :
yum install vim-X11 vim-common vim-enhanced vim-minimal
Once done you can enjoy the full benefits of a full featured and very powerful text editor.
Hope you’ll find this useful!