LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices



Reply
 
Search this Thread
Old 02-23-2013, 07:12 PM   #1
angel'le
LQ Newbie
 
Registered: Apr 2012
Distribution: Gentoo, Arch
Posts: 21

Rep: Reputation: Disabled
How to backup root's bash history as normal user


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

Thanks in advance

Last edited by angel'le; 02-23-2013 at 07:13 PM.
 
Old 02-23-2013, 07:33 PM   #2
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,618
Blog Entries: 1

Rep: Reputation: Disabled
You may be the owner of a Big Fat Re-install if you keep re-assigning ownership of important directories.
 
Old 02-23-2013, 07:48 PM   #3
angel'le
LQ Newbie
 
Registered: Apr 2012
Distribution: Gentoo, Arch
Posts: 21

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
You may be the owner of a Big Fat Re-install if you keep re-assigning ownership of important directories.
That is why I want try the correct way, but I don't know what to do.
 
Old 02-23-2013, 09:28 PM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
After doing your work as root, before invoking the exit cmd, once invoke:
Code:
[user@example]~# history >> /home/username/root_bash_history.txt
[user@example]~# exit
You can also add your user account to /etc/sudoers and get sudo privilages, then you can:
Code:
[user@example]~$ date >> /home/username/root_bash_history.txt
[user@example]~$ sudo cat /root/.bash_history >> /home/username/root_bash_history.txt
[sudo] password for username:
Besides, many other ways to achieve this, so let's know where exactly you're stuck?

Last edited by shivaa; 02-23-2013 at 09:31 PM.
 
Old 02-24-2013, 09:10 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,679
Blog Entries: 54

Rep: Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955Reputation: 2955
Quote:
Originally Posted by angel'le View Post
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).
 
1 members found this post helpful.
Old 02-24-2013, 07:42 PM   #6
angel'le
LQ Newbie
 
Registered: Apr 2012
Distribution: Gentoo, Arch
Posts: 21

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by unSpawn View Post
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.

Thank all you
 
Old 02-27-2013, 08:13 PM   #7
abefroman
Senior Member
 
Registered: Feb 2004
Location: Chicago
Distribution: CentOS
Posts: 1,277

Rep: Reputation: 53
If you install Snoopy Logger there will be a copy in /var/log/secure
 
  


Reply

Tags
file, permission, root


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] NetworkManager isn't behaving properly in normal user, but works well in root user. MarkZar Linux - Networking 1 02-17-2013 12:32 AM
How to get root user PATH from normal user nagendrar Linux - Newbie 11 08-23-2011 09:40 PM
How to run daemon process being a normal user [not root user]. narendra1310 Linux - Software 1 10-26-2009 10:48 AM
super user privileges check for a normal user in bash script freeindy Programming 2 08-01-2008 07:08 AM
Games runs slow as normal user, but fast as root user mcore Linux - Software 2 06-08-2004 12:11 AM


All times are GMT -5. The time now is 03:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration