Sponsored Content
Operating Systems Linux SuSE Auditors want more security with root to root access via ssh keys Post 302831719 by Corona688 on Thursday 11th of July 2013 02:48:41 PM
Old 07-11-2013
I have this in my ~/.bashrc

Code:
# If ssh agent strings already set, and the PID is valid,
# no further work is needed.
[ ! -z "${SSH_AGENT_PID}" ]             &&
        [ -d "/proc/${SSH_AGENT_PID}" ] &&
        return

function ssh_agent_kill
{
        [ -z "$SSH_AGENT_PID" ] && return

        if flock -w 0 -x 200
        then
                echo "We are the last.  Killing $SSH_AGENT_PID"
                kill "$SSH_AGENT_PID" ||
                        echo "WARNING, ssh-agent $SSH_AGENT_PID not killed" >&2
                : > ~/.ssh_agent
                chmod 600 ~/.ssh_agent
                flock -u 200
        fi
}

[ ! -f ~/.ssh-agent ] && touch ~/.ssh-agent && chmod 600 ~/.ssh_agent

# Open file so we can play with locks
exec 200<~/.ssh-agent

NEW_AGENT=0

if flock -w 1 -x 200
then
        echo "Creating new ssh-agent instance" >&2
        :>~/.ssh-agent
        chmod 600 ~/.ssh-agent
        ssh-agent -s > ~/.ssh-agent
        NEW_AGENT=1
elif [ ! -d "/proc/${SSH_AGENT_PID}" ]
then
        cat <<EOF >&2
PID ${SSH_AGENT_PID} no longer exists, but you still have sessions open.
Please close these sessions, then source $0 again to create a new
instance.
EOF

fi

# Make it a shared lock, to signify its readable
if ! flock -w 1 -s 200
then
        echo "We cannot share-lock"
        return 2>/dev/null || exit 1
fi

source ~/.ssh-agent

[ "${NEW_AGENT}" == 1 ] && ssh-add

trap "ssh_agent_kill" EXIT

So when I login to my local account, it loads ssh-agent which adds my keys (asking once for my passwords). Further simultaneous logins do not get asked.

If my shell sessions are hard-killed for some reason, that might leave ssh-agent hanging, so I added this to my own (not root's!) crontab:

Code:
* 1 * * *       /usr/bin/killall ssh-agent ; true

...which means in the morning, I login and ssh-agent loads my keys for the duration of the workday, and I can 'ssh -t servername exec sudo bash' to get passwordless root prompts if I really need to.

At the end of the day, the last logout kills ssh-agent automatically. And if it should happen to be missed because of a hard-kill or other problem, it will be killed automatically at 1am.

Last edited by Corona688; 07-11-2013 at 03:54 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Run non-root script as root with non-root environment

All, I want to run a non-root script as the root user with non-root environment variables with crontab. The non-root user would have environment variables for database access such as Oracle or Sybase. The root user does not have the Oracle or Sybase enviroment variables. I thought you could do... (2 Replies)
Discussion started by: bubba112557
2 Replies

2. Linux

how to access root priveliges if root password is lost

wish to know how to access root password it root password is forgotten in linux (1 Reply)
Discussion started by: wojtyla
1 Replies

3. SCO

root access

We have SCO 5.0.5 and can't log into system as "root". The system indicates the password is incorrect. No one knows what happened. How can we resolve this issue.. Are there files we can restore from backup...? Any suggestions would be appreciated. Thank you.. (2 Replies)
Discussion started by: RBurer
2 Replies

4. Solaris

Security of root access

Hi, The security auditor give a this statement , what to do ? On my solaris system (S10) "The User ID "root" should not be used on the system - the su and the priviledged account should be used from each administrator for accountability purposes" What to do ? (3 Replies)
Discussion started by: falcon16
3 Replies

5. AIX

root access

Hello I have a question. I have a box with Aix 5.3 but I want to disable root access direct from any terminal or console. I mean If I want to login to 10.10.10.10 login:root password ********* Root access is not permited Which file I have to edit. to the users first login with... (4 Replies)
Discussion started by: lo-lp-kl
4 Replies

6. Linux

RSA Keys root account problem?

I have set up RSA private and pub keys between "NodeA" and "NodeB" Everything works fine when I test with a regular user account. However it does not work as root. I followed the same procedure to set up the keys as the root user but I am still prompted for a password. I have verified my... (1 Reply)
Discussion started by: geek4lif
1 Replies

7. UNIX for Dummies Questions & Answers

How to allow access to some commands having root privleges to be run bu non root user

hi i am new to unix and i have abig task. i have to \run particular commands having root privileges from a non root user. i know sudo is one of the way but i need sum other approach kindly help Thanks (5 Replies)
Discussion started by: suryashikha
5 Replies

8. Solaris

Migration of system having UFS root FS with zones root to ZFS root FS

Hi All After downloading ZFS documentation from oracle site, I am able to successfully migrate UFS root FS without zones to ZFS root FS. But in case of UFS root file system with zones , I am successfully able to migrate global zone to zfs root file system but zone are still in UFS root file... (2 Replies)
Discussion started by: sb200
2 Replies

9. Shell Programming and Scripting

How to give root access to non root user?

Currently in my system Red Hat is installed. And Many user connect to my machine via SSH Techia Terminal. I want to give some users a root level access. Can anyone please help me how to make it possible. I too searched on the Google but didn't find the correct way Regards ADI (4 Replies)
Discussion started by: adisky123
4 Replies

10. Ubuntu

Root access that can't change root password?

We are having a little problem on a server. We want that some users should be able to do e.g. sudo and become root, but with the restriction that the user can't change root password. That is, a guarantee that we still can login to that server and become root no matter of what the other users will... (2 Replies)
Discussion started by: 244an
2 Replies
SSH-COPY-ID(1)						      General Commands Manual						    SSH-COPY-ID(1)

NAME
ssh-copy-id - install your public key in a remote machine's authorized_keys SYNOPSIS
ssh-copy-id [-i [identity_file]] [user@]machine DESCRIPTION
ssh-copy-id is a script that uses ssh to log into a remote machine and append the indicated identity file to that machine's ~/.ssh/autho- rized_keys file. If the -i option is given then the identity file (defaults to ~/.ssh/id_rsa.pub) is used, regardless of whether there are any keys in your ssh-agent. Otherwise, if this: ssh-add -L provides any output, it uses that in preference to the identity file. If the -i option is used, or the ssh-add produced no output, then it uses the contents of the identity file. Once it has one or more fin- gerprints (by whatever means) it uses ssh to append them to ~/.ssh/authorized_keys on the remote machine (creating the file, and directory, if necessary.) NOTES
This program does not modify the permissions of any pre-existing files or directories. Therefore, if the remote sshd has StrictModes set in its configuration, then the user's home, ~/.ssh folder, and ~/.ssh/authorized_keys file may need to have group writability disabled manu- ally, e.g. via chmod go-w ~ ~/.ssh ~/.ssh/authorized_keys on the remote machine. SEE ALSO
ssh(1), ssh-agent(1), sshd(8) OpenSSH 14 November 1999 SSH-COPY-ID(1)
All times are GMT -4. The time now is 02:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy