LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Multiple Questions - can't find answers anywhere (https://www.linuxquestions.org/questions/linux-newbie-8/multiple-questions-cant-find-answers-anywhere-783754/)

Morgandy 01-21-2010 09:24 AM

Multiple Questions - can't find answers anywhere
 
Hi All,

I need the following information:

- When using SU - , I need the option to show the full user path (root user, home dir, etc..), not just root@name. Is there one?

-If not in sudoers file, how can a user get in to edit a file for example. Is that possible?

-Does service ssh restart disconnect users?

Thanks greatly!

Agrouf 01-21-2010 09:44 AM

Quote:

Originally Posted by Morgandy (Post 3835082)
- When using SU - , I need the option to show the full user path (root user, home dir, etc..), not just root@name. Is there one?

You can use the PS1 environment variable in ~/.bashrc
edit ~/.bashrc and add the folling line at the end:
Code:

export PS1="[\u@\h:\w]\$"
Quote:

-If not in sudoers file, how can a user get in to edit a file for example. Is that possible?
With a text editor, like gedit, vi, or emacs. Why do you need the sudoers file to edit a file anyway? Do you mean to edit a file you don't have the right to edit? Just give the user the right to edit and he can edit.
Quote:

-Does service ssh restart disconnect users?
Users connected via ssh, yes, definitely.

sarum1990 01-21-2010 09:48 AM

In regards to your first question I believe you should look at the man page for whatever shell you are using under prompting. For instance in BASH you can change the prompt by setting $PS1 to different things.

If a user is not in the sudoers file they can su root if they have the root password to switch to the root user and perform administrative tasks requiring such privileges.

Restarting ssh will disconnect users.

Hope this helps.

portamenteff 01-21-2010 10:21 AM

answers (or some of them)
 
Morgandy,
The default prompt comes from the PS1 environment variable. You could do set this in this way:
Code:

su
(enter password:)
PS1=\u@\w\h
export $PS1
echo $PS1

The PS1 is an environment variable. This is a temporary fix. If you want to change it permanently, you need to (as root) open /etc/profile and find the part of this shell program that defines PS1. I don't recommend this for newer users. You can paste this code into a .txt file and put in an easily accessible directory and just run it whenever you want to use this prompt. This is how I do it. I simply type:
Code:

chmod u+x /home/john/shellPrompt
./home/john/shellPrompt

because that's what I named the thing. (note once you set permission will chmod it will stay that way until you change it.
Up there in the line that starts with "PS1", is a "\u" for user, "@" which is a string, "\w" working directory, "\h" for hostname. You can leave the h out if you want or add "\t", "\d" date and time. The "\" is nessecary as an escape character. If you don't put the \ in there your prompt will look like this
Code:

u@wh#
Nice huh? I learned this the hard way so you won't have to.

As to the SU question, you can edit any file that you have permission to, unless you have the root password, then you can edit any file on the machine!
I do use "sudo" occasionally, but SU is better because you don't have to type "sudo" every time you want permission, there is no limit to SU's permission.
If I want to edit a file in a graphical text editor I type
Code:

sudo gedit fileName
but I generally use vi for root editing.
Code:

SU
vi fileName

As for the SSH question: No. If the connection times out, the client will have to log in again. It's not that much of a task, so I never complained about it. Remember to always save your work. Save it early, and often.
Hope that helps.

chrism01 01-21-2010 05:11 PM

Note that Linux is case sensitive, so the cmd is su not SU.
Also,

su -

gives you root's env

su

(no '-') logs you in as root, BUT with your orig env...

Actually, you can switch to any user via su, if you know the passwd. It just defaults to root if you don't specify one.

brianL 01-21-2010 06:30 PM

Quote:

Originally Posted by Morgandy (Post 3835082)
-If not in sudoers file, how can a user get in to edit a file for example. Is that possible?

Two examples:
In KDE:
Code:

kdesu kwrite whatever file name
In Gnome:
Code:

gksu gedit whatever file name
Followed in both cases with root's password.


All times are GMT -5. The time now is 01:54 PM.