1

so, I have ssh setup on a Linux machine to start screen when user (root) logs in on ssh (on a basically single-user machine) I have dataplicity installed too, so I can access it from anywhere. when I remote to it, it runs as user dataplicity, so I su as root user to do anything, which doesn't reconnect to any available screen sessions. is there a way to add things that happens after 'su' only for a specific user?

1
  • It's not even so much that we don't understand the question, it's that we're wondering what the hell you're trying to accomplish, because chances are that the method you're asking for is the wrong way to go about it. – Shadur Aug 18 '17 at 8:49
0

When you su - to any user ID it means that you login to that ID . There is file on user home directory which read after user logged in . In recent Linux it's ~/.profile or in older version ~/.bash_profile . You can add anything which start when user logged in in this file . If you couldn't find these files on user home directory try to edit ~/.bashrc .

3
  • But this will be executed for all root logins. As I understand the question, the screen session should only be reattached if user dataplicity sus into root account. – Philippos Aug 17 '17 at 5:35
  • He can put screen -r in any user .profile so whenever user login screen will attached again . – Ali Ghasempour Aug 17 '17 at 5:52
  • Either you don't understand what I'm trying to say or the other way around, so I better keep out of it. – Philippos Aug 17 '17 at 6:16
0

su stands for "switch user" and logs you in as the user you indicate. If you don't indicate a user, then you log in as root.

The - invokes a new login shell, which cleans your slate of environment variables.

If it is safe to do so, you can use sudo to run a command as a privileged user, while remaining logged in as dataplicity. For example:

sudo lastb

The machine will ask you for the dataplicity login and then run lastb (checks for failed logins) as a privileged user.

In order to use sudo from your dataplicity account, you would need to add dataplicity to your /etc/sudoers account (in SUSE). Do this by using:

su -

visudo

Then add: dataplicity ALL=(ALL) ALL to the list. Usually you add it right after the root ALL=(ALL) ALL entry.

5
  • 1
    While all of this is true and well explained, it doesn't seem to address the question: How to attach to a running screen session automatically only when suing from a specific user? – Philippos Aug 17 '17 at 5:32
  • I am suggesting to use sudo on commands instead of logging into root with su -. That way, commands such as screen should be run from and apply to the dataplicity account instead of to the root account. It should also not wipe out the environmental variables opened by dataplicity. But that's assuming the specific user that pcs3rd wants sudo actions applied to is the dataplicity account. – SinecureLife Aug 18 '17 at 0:34
  • I don't believe he wants that, but he seems to have lost interest in the answer, so I vote to close the question. – Philippos Aug 18 '17 at 7:29
  • ... im using Kali – pcs3rd Aug 19 '17 at 13:56
  • Kali and SUSE are both Debian based, so the above command should work. If that's what you're looking for. – SinecureLife Aug 20 '17 at 0:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.