[SOLVED] How to backup root's bash history as normal user
Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I type important commands as root but sometimes either my hard disk fails or my system crashes.
Therefore I want to automatically backup with dropbox the /root/.bash_history file as a normal user.
The only thing I need is get acess to this file without root privileges.
I tried adding myself as owner of /root/ folder, but it is insecure
I want to automatically backup with dropbox the /root/.bash_history file as a normal user.
Be aware that 0) you obviously should address causes for outage / b0rkage first and 1) that DropBox does not guarantee privacy. With shell history files the potential risk exists of disclosing sensitive information so you best encrypt files before stashing them. Couple of possibilities:
- Set up a regular cron job that triggers a backup. Note here the cron job interval doesn't matter because it won't trigger any action if the file hash matches:
Code:
#!/bin/sh --
# Set debug mode when testing:
set -vx
# Set default behaviour:
LANG=C; LC_ALL=C; export LANG LC_ALL
TARGET="/root/.bash_history"
HASHFILE="/root/.bash_history.sha1"
[ -f "${HASHFILE}" ] || sha1sum "${TARGET}" > "${HASHFILE}"
sha1sum --status -c "${HASHFILE}" || do_make_backup_etc_etc
exit 0
- Set up a incron job that triggers a backup on say IN_MODIFY and IN_CLOSE_WRITE events,
- Configure /etc/sudoers so you can copy that particular file manually (or from your personal crontab).
Be aware that 0) you obviously should address causes for outage / b0rkage first and 1) that DropBox does not guarantee privacy. With shell history files the potential risk exists of disclosing sensitive information so you best encrypt files before stashing them. Couple of possibilities:
- Set up a regular cron job that triggers a backup. Note here the cron job interval doesn't matter because it won't trigger any action if the file hash matches:
Code:
#!/bin/sh --
# Set debug mode when testing:
set -vx
# Set default behaviour:
LANG=C; LC_ALL=C; export LANG LC_ALL
TARGET="/root/.bash_history"
HASHFILE="/root/.bash_history.sha1"
[ -f "${HASHFILE}" ] || sha1sum "${TARGET}" > "${HASHFILE}"
sha1sum --status -c "${HASHFILE}" || do_make_backup_etc_etc
exit 0
- Set up a incron job that triggers a backup on say IN_MODIFY and IN_CLOSE_WRITE events,
- Configure /etc/sudoers so you can copy that particular file manually (or from your personal crontab).
I get almost of this method, actually it looks pretty good. So after the last double pipeline I will copy the history to an encrypted folder I use to dropbox and finally regenerate the hash file.
I'm going to use the root crontab, so it is not need to configure the sudoers file.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.