Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Send mail at root session opening

  1. #1

    Default Send mail at root session opening

    Hi there

    On a server, based on OpenSUSE 13.2, I would like to keep informed about root activity by sending me a message at session opening with su. So basically, I have just a sendmail command to put somewhere.

    On a previous setup based on OpenSUSE 12.3, putting this line on the root's .profile file was sufficient, but with 13.2, this doesn't work anymore.

    I have read that a non login shell (as I do with su) shouldn't read the .profile file, so I'm quite puzzled, since it actually used to work. A turnaround would be to put this line in root's .bashrc file, but by instance if I su to my root account, open tmux and split it in two, I will receive 3 notifications in total, and that's not convenient.

    So what should I do? Thanks for your answers.

  2. #2
    Join Date
    Jul 2008
    Location
    Seattle, WA
    Posts
    17,079

    Default Re: Send mail at root session opening

    On Sat, 31 Jan 2015 23:06:02 +0000, Neraste wrote:

    > Hi there
    >
    > On a server, based on OpenSUSE 13.2, I would like to keep informed about
    > root activity by sending me a message at session opening with su. So
    > basically, I have just a sendmail command to put somewhere.
    >
    > On a previous setup based on OpenSUSE 12.3, putting this line on the
    > root's .profile file was sufficient, but with 13.2, this doesn't work
    > anymore.
    >
    > I have 'read' (http://tinyurl.com/maaflog) that a non login shell (as I
    > do with su) shouldn't read the .profile file, so I'm quite puzzled,
    > since it actually used to work. A turnaround would be to put this line
    > in root's .bashrc file, but by instance if I su to my root account, open
    > tmux and split it in two, I will receive 3 notifications in total, and
    > that's not convenient.
    >
    > So what should I do? Thanks for your answers.


    ..bash_login still runs, IIRC, so that should work.

    Jim



    --
    Jim Henderson
    openSUSE Forums Administrator
    Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

  3. #3

    Default Re: Send mail at root session opening

    Hi,

    If bash is the log-in shell then you can try

    Code:
    ~/.bash_profile
    "Unfortunately time is always against us" -- [Morpheus]

    .:https://github.com/Jetchisel:.

  4. #4
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,487
    Blog Entries
    2

    Default Re: Send mail at root session opening

    If not working as expected,
    It would probably be useful to post in detail exactly what you are doing.

    So, for instance I'm going to hazard a guess that you made your original changes directly to a file that was replaced during upgrade.
    This is why for instance the comments in /etc/profile explicitly say you should not edit that file directly but should instead create a new file "/etc/profile.local" that would survive an upgrade.

    An alternate way to make profile changes that are survivable is to create a file with your alternations in the folder /etc/profile/

    TSU

  5. #5
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,396

    Default Re: Send mail at root session opening

    Quote Originally Posted by Neraste View Post
    Hi there

    On a server, based on OpenSUSE 13.2, I would like to keep informed about root activity by sending me a message at session opening with su. So basically, I have just a sendmail command to put somewhere.

    On a previous setup based on OpenSUSE 12.3, putting this line on the root's .profile file was sufficient, but with 13.2, this doesn't work anymore.

    I have read that a non login shell (as I do with su) shouldn't read the .profile file, so I'm quite puzzled, since it actually used to work. A turnaround would be to put this line in root's .bashrc file, but by instance if I su to my root account, open tmux and split it in two, I will receive 3 notifications in total, and that's not convenient.

    So what should I do? Thanks for your answers.
    BTW using
    Code:
    su
    instead of
    Code:
    su -
    i a security issue.

    And this is in the bash man page:
    When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc then ~/.bashrc when those files exist and are readable. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.
    So using .bashrc might help.

    But again, for security reasons, you shoud try to learn the habit of using a login shell.
    Henk van Velden

  6. #6

    Default Re: Send mail at root session opening

    Thank you guys for your answers. Arf, stupid I am! My root shell isn't Bash, but Zsh. So when I said to modify .bashrc, I meant to modify .zshrc. Sorry for that m(_ _)m .

    Quote Originally Posted by tsu2 View Post
    If not working as expected,
    It would probably be useful to post in detail exactly what you are doing.
    I'm doing the following: I connect to my server by SSH with a user account (root login by SSH is disabled for security reasons) and then switch to root session with:

    Code:
    user@server $ su
    Welcome
    root@server #
    Quote Originally Posted by hcvv View Post
    BTW using
    Code:
    su
    instead of
    Code:
    su -
    i a security issue.

    -snip-

    But again, for security reasons, you shoud try to learn the habit of using a login shell.
    I have just found Zsh doesn't source .profile file but .zprofile instead, only if you use su - .

    I didn't know using bare su was a bad practice, so I'm considering to change my habit. But how can I force the user account to use su - instead of su (without using alias)?

  7. #7
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,396

    Default Re: Send mail at root session opening

    Quote Originally Posted by Neraste View Post

    I didn't know using bare su was a bad practice, so I'm considering to change my habit. But how can I force the user account to use su - instead of su (without using alias)?
    I assume that only very few users (maybe only one, but that depends on how big your "company" is) know the root password. I also assume that they are very responsable and disciplined people. As I said, it is a habit. You and those few (if they exist) have to start getting that habit from now on.
    Henk van Velden

  8. #8
    Join Date
    Nov 2009
    Location
    West Virginia Sector 13
    Posts
    15,769

    Default Re: Send mail at root session opening

    Difference between su and su -

    su gives root authority but the environment for the session remains the original user

    so - give full root authority plus full root environment.

    It is subtle but there is a difference

  9. #9
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,396

    Default Re: Send mail at root session opening

    Quote Originally Posted by gogalthorp View Post
    It is subtle but there is a difference
    For me it is not that subtle. It rings alarm bells
    Henk van Velden

  10. #10
    Join Date
    Nov 2009
    Location
    West Virginia Sector 13
    Posts
    15,769

    Default Re: Send mail at root session opening

    Well you can use the knowledge to do more then if you did not have it.


Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •