DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 28th October 2020
PingPing's Avatar
PingPing PingPing is offline
Real Name: Hammond
Port Guard
 
Join Date: Jan 2015
Location: United Kingdom
Posts: 18
Default How do I set PS1 after 'su'? [RESOLVED]

I have my ~/.profile as:
Code:
PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games
export PATH HOME TERM

PS1='$ '
and I get the desired prompt when I login:
Code:
$
However, when I
Code:
$ su
and enter root's password, the prompt changes to
Code:
openbsd#
where 'openbsd' is the first part of hostname.
Please could someone explain to me how do I set this prompt so that when is 'su' the prompt just shows
Code:
#
I'm running stock OpenBSD 6.8 RELEASE.

Last edited by PingPing; 1st November 2020 at 08:08 AM. Reason: Resolved.
Reply With Quote
  #2   (View Single Post)  
Old 28th October 2020
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,128
Default

After $ su you can do:

Code:
export PS1='# '
To make it automatic you edit the .profile file in the root home directory and set PS1 to '# '.
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #3   (View Single Post)  
Old 28th October 2020
fvgit's Avatar
fvgit fvgit is offline
Spikes in tights
 
Join Date: May 2016
Location: perl -MMIME::Base64 -le 'print decode_base64("U2hlcndvb2QgRm9yZXN0")'
Posts: 314
Default

Quote:
Originally Posted by J65nko View Post
To make it automatic you edit the .profile file in the root home directory and set PS1 to '# '.
Wouldn't he have to use the '-l' flag with su for .profile to be read automatically?
Reply With Quote
  #4   (View Single Post)  
Old 29th October 2020
PingPing's Avatar
PingPing PingPing is offline
Real Name: Hammond
Port Guard
 
Join Date: Jan 2015
Location: United Kingdom
Posts: 18
Default

Quote:
Originally Posted by fvgit View Post
Wouldn't he have to use the '-l' flag with su for .profile to be read automatically?
Yes, and I'm also put into /root if I invoke 'su -l', which I would prefer to avoid.

It seems odd to me that when I login, I'm greeted with
Code:
foo$
and when I 'su' this goes to
Code:
foo#
If there was a way to find out where the $ -> # happens, I could then edit that code (to remove 'foo' in both instances).
Reply With Quote
  #5   (View Single Post)  
Old 29th October 2020
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 461
Default

Quote:
Originally Posted by PingPing View Post
If there was a way to find out where the $ -> # happens, I could then edit that code (to remove 'foo' in both instances).
PS1 is specified in /etc/ksh.kshrc:

https://github.com/openbsd/src/blob/.../ksh.kshrc#L33

Any changes to that file will be lost if the base file set is upgraded.
__________________
Are you infected with Wetiko?

Last edited by Head_on_a_Stick; 29th October 2020 at 09:00 AM. Reason: s|ksh/kshrc|ksh.kshrc|'
Reply With Quote
  #6   (View Single Post)  
Old 30th October 2020
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,128
Default

From ksh(1)
Quote:
PS1
The primary prompt for interactive shells. Parameter, command, and arithmetic substitutions are performed, and the prompt string can be customised using backslash-escaped special characters.
........
The default prompt is the first part of the hostname, followed by ‘$ ’ for non-root users, ‘# ’ for root.
I have this in .profile:
Code:
PS1="\u@\h[\w]"
export PS1
This gives me a prompt like:
Code:
root@alix[~]cd /var/log
root@alix[/var/log]
What is the prompt if you do $ su root?
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #7   (View Single Post)  
Old 30th October 2020
sabrina sabrina is offline
Port Guard
 
Join Date: Jun 2020
Posts: 15
Default

~/.profile executes once per logon, the value of $ENV executes every time ksh starts.
Add this line into ~/.xsession and ~/.profile
Code:
export ENV=$HOME/.kshrc
Add this content to ~/.kshrc
Code:
currentUserName=$(whoami)
if [ $currentUserName == 'root' ]; then
  PS1='# '
else
  PS1='$ '
fi
Reply With Quote
  #8   (View Single Post)  
Old 30th October 2020
gustaf gustaf is offline
Fdisk Soldier
 
Join Date: Dec 2016
Posts: 68
Default

Hi PingPing,

Just a question -- not necessarily to answer here, but to think about. Why are you using su to run commands as root?

The recommended way to execute commands requiring root permission is to use $ doas. You run this command as a regular user, using your own password.

doas(1) - DESCRIPTION
Quote:
The default [user] is root.

OpenBSD - FAQ - System management - Executing Commands as Another User (emphasis mine):
Quote:
The doas(1) tool lets a system administrator permit certain users to run specific commands as another user. Regular users can run administrative commands, only being required to authenticate as themselves, without the need for the root password.
This command in its most basic form is simple: $ doas <command>. Type your user password at the prompt and the command will execute as root. All other commands will be run with regular-user privileges.
Reply With Quote
  #9   (View Single Post)  
Old 1st November 2020
PingPing's Avatar
PingPing PingPing is offline
Real Name: Hammond
Port Guard
 
Join Date: Jan 2015
Location: United Kingdom
Posts: 18
Default

@J65nko
As explained below, I'm trying to keep my keystrokes down to a minimum so 'su root' is a bridge too far for me.

@sabrina
Thanks. That gives me what I'm looking for.

@gustaf
Yes, I do use 'doas'. However, when I'm doing admin work that requires repeated 'doas', it gets tedious. Otherwise, I do use 'doas'.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:14 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick