Recent

Author Topic: Executar como root (Linux)  (Read 1201 times)

RobsonD

  • New Member
  • *
  • Posts: 17
Executar como root (Linux)
« on: August 29, 2019, 04:13:03 pm »
Ae pessoal, boas.

Minha questão é, como executar um comando do Linux em modo root?
Antes de ser executado, solicitasse (numa janela) a senha de root.

O comando a usar seria: cat /proc/cpuinfo

Gostaria de usar TProcess

Grato

RobsonD

  • New Member
  • *
  • Posts: 17
Re: Executar como root (Linux)
« Reply #1 on: August 29, 2019, 05:36:06 pm »
Consegui

pkexec

...é o comando inicial.

RobsonD

  • New Member
  • *
  • Posts: 17
Re: Executar como root (Linux)
« Reply #2 on: August 29, 2019, 05:45:00 pm »
Agora, a dúvida seria...

De posse dessa senha (capturo ela no retorno da função)

como uso novamente sem precisar solicitar que o usuário digite a senha?

Eu uso o TProcess, ao finalizar pego o retorno e gravo numa string, se for fazer o processo novamente, de posse dessa senha, como deveria ser usado?

andersonscinfo

  • Full Member
  • ***
  • Posts: 112
Re: Executar como root (Linux)
« Reply #3 on: April 25, 2020, 04:12:21 am »
Ola, poderia postar seu codigo de como fez para executar um comando como root?

Att.

JiaXing

  • Jr. Member
  • **
  • Posts: 75
Re: Executar como root (Linux)
« Reply #4 on: April 25, 2020, 04:19:18 am »
Ae pessoal, boas.

Minha questão é, como executar um comando do Linux em modo root?
Antes de ser executado, solicitasse (numa janela) a senha de root.

O comando a usar seria: cat /proc/cpuinfo

Gostaria de usar TProcess

Grato

I don't understand the language but your command `cat /proc/cpuinfo ` ran just fine on my Linux Mint with normal user account. I think root is not needed.
I'm subscribed to the church of 440bx. Say no to OOP  :P

Thaddy

  • Hero Member
  • *****
  • Posts: 10446
Re: Executar como root (Linux)
« Reply #5 on: April 25, 2020, 09:22:02 am »
Indeed, root is not needed:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}
  2. uses
  3.   classes;
  4. var
  5.   s:Tstringlist;
  6. begin
  7.   s:= Tstringlist.create;
  8.   try
  9.     s.LoadFromFile('/proc/cpuinfo');
  10.     writeln(s.Text);
  11.   finally
  12.     s.Free;
  13.   end;
  14. end.
When you ask a question that is actually answered in the documentation, you are either lazy or a moron.

MarkMLl

  • Hero Member
  • *****
  • Posts: 1219
Re: Executar como root (Linux)
« Reply #6 on: April 25, 2020, 09:32:00 am »
Agreed, elevated privilege isn't needed for that. And for things like accessing low-numbered network ports POSIX capabilities work well, and can be debugged using gdbserver.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

Otto

  • Full Member
  • ***
  • Posts: 225
Re: Executar como root (Linux)
« Reply #7 on: April 25, 2020, 09:44:17 am »
I could be wrong because I don't speak Portuguese.
I suppose the command is just an example.
I think the main question can be translated into English as follows:

Before running a command in Linux in root mode, how can I ask for the root password in a window?
Kind regards.

JiaXing

  • Jr. Member
  • **
  • Posts: 75
Re: Executar como root (Linux)
« Reply #8 on: April 25, 2020, 09:49:07 am »
I could be wrong because I don't speak Portuguese.
I suppose the command is just an example.
I think the main question can be translated into English as follows:

Before running a command in Linux in root mode, how can I ask for the root password in a window?

OK. If it's so I recommend him to use gksudo and add gksu as part of requirement packages to use his software.
I'm subscribed to the church of 440bx. Say no to OOP  :P

MarkMLl

  • Hero Member
  • *****
  • Posts: 1219
Re: Executar como root (Linux)
« Reply #9 on: April 25, 2020, 09:58:38 am »
OK. If it's so I recommend him to use gksudo and add gksu as part of requirement packages to use his software.

Or kdesudo etc. as appropriate. However I'm not sure that all versions of every distro can be relied on to supply this, and it should only be used as a last resort. Same considerations apply to setuid root.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

andersonscinfo

  • Full Member
  • ***
  • Posts: 112
Re: Executar como root (Linux)
« Reply #10 on: April 25, 2020, 12:28:00 pm »
Seria possivel passar a senha do root como parametro, para assim não precisar solicitar a senha ao usuario?

Att.

Thaddy

  • Hero Member
  • *****
  • Posts: 10446
Re: Executar como root (Linux)
« Reply #11 on: April 25, 2020, 01:06:38 pm »
note my example does the same as cat /proc/cpuinfo why the fuss? Works n all distro's in usermode
When you ask a question that is actually answered in the documentation, you are either lazy or a moron.

andersonscinfo

  • Full Member
  • ***
  • Posts: 112
Re: Executar como root (Linux)
« Reply #12 on: April 25, 2020, 01:11:35 pm »
@Thaddy, compreendo, mas queria saber se é possivel passar senha do root por parametro ou alguma forma de executar um comando como root de forma silenciosa?

ps: talvez essa questão não seja bem parte do forum, mas fiquei curioso.

Att.

lucamar

  • Hero Member
  • *****
  • Posts: 3019
Re: Executar como root (Linux)
« Reply #13 on: April 25, 2020, 01:54:54 pm »
queria saber se é possivel passar senha do root por parametro ou alguma forma de executar um comando como root de forma silenciosa?

Use "sudo -S"; você pode passar a senha gravando-a (seguida por um caractere de nova linha) no fluxo TProccess.Input.

Exemplo de linha de comando:
Code: [Select]
sudo -S cat /proc/cpuinfo < paswordfile
Use "sudo -S"; you can then pass the password by writing it (followed by a new-line character) to the TProccess.Input stream.

Command line example:
Code: [Select]
sudo -S cat /proc/cpuinfo < paswordfile
« Last Edit: April 25, 2020, 01:58:41 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

andersonscinfo

  • Full Member
  • ***
  • Posts: 112
Re: Executar como root (Linux)
« Reply #14 on: April 25, 2020, 02:14:23 pm »
@lucamar

Obrigado, funciona muito bem, você é extraordinario.

Thank you, it works very well, you are extraordinary.


Att

 

TinyPortal © 2005-2018