Linux - change the hostname in the CLI
you can type "hostname HOSTNAME" where HOSTNAME is the new name you want. The next time you log in / connect via ssh, that's what you'll see.
How to hide the hostname on the terminal on linux?
If you want a temporary solution(since you are talking about a screencast), you can set your PS1
variable to change the prompt.
For example, if you want your prompt to be:
$
Then set your PS1
variable as follows on the terminal:
export PS1='$ '
Likewise, you can have it to whatever you want the prompt to look like. If you want the path to be displayed, set it as:
export PS1='\w '
For a permanent solution, you can set this in your shell configuration script, which is your ~/.bashrc
file in case you have bash as your shell.
Change hostname on SSH session
Like Matt said. There is similar question on Unix.stackexchange
And you find some Background
here
Modify PS11
PS1="touch me : "
Bash - PS1 not Updating With Proper Hostname after Hostname Change in Script
There is no way to make Bash to update the value which the \h
is translated to. It is read once at startup and is not modified afterwards. So the only options if you need to get an updated prompt are:
- start a subshell —
bash
- replace current shell with a new one —
exec bash
- update PS1, replacing
\h
with$(hostname)
or a literal string
Now, more into Bash internals. The hostname value is kept in the current_host_name
variable, which is defined in shell.h:113
:
extern char *current_host_name;
It is used in three places, variables.c:695
:
temp_var = set_if_not ("HOSTNAME", current_host_name);
parse.y:6039
:
case 'h':
case 'H':
t_host = savestring (current_host_name);
if (c == 'h' && (t = (char *)strchr (t_host, '.')))
...
and y.tab.c:8333
:
case 'h':
case 'H':
t_host = savestring (current_host_name);
if (c == 'h' && (t = (char *)strchr (t_host, '.')))
...
And it is assigned a value only once (besides initialization with an empty string) in the shell_initialize()
function in shell.c:1918
:
/* It's highly unlikely that this will change. */
if (current_host_name == 0)
{
/* Initialize current_host_name. */
if (gethostname (hostname, 255) < 0)
current_host_name = "??host??";
else
current_host_name = savestring (hostname);
}
All the line numbers and file names are from the source code from bash-5.1.tar.gz
from the mirror at kernel.org.
Change the From: address in Unix mail
In my version of mail ( Debian linux 4.0 ) the following options work for controlling the source / reply addresses
- the -a switch, for additional headers to apply, supplying a From: header on the command line that will be appended to the outgoing mail header
- the $REPLYTO environment variable specifies a Reply-To: header
so the following sequence
export REPLYTO=cms-replies@example.com
mail -aFrom:cms-sends@example.com -s 'Testing'
The result, in my mail clients, is a mail from cms-sends@example.com, which any replies to will default to cms-replies@example.com
NB: Mac OS users: you don't have -a , but you do have $REPLYTO
NB(2): CentOS users, many commenters have added that you need to use -r
not -a
NB(3): This answer is at least ten years old(1), please bear that in mind when you're coming in from Google.
Adding host name to /etc/hosts in Linux
dhcpcd has a -c/--script
option to run an external script anytime it configures or brings up an interface. You can use this to manually update the hosts file with the configured hostname.
Postgresql - adding hostname / port to commandline
Yes, you can use environment variables PGHOST and PGPORT.
See https://www.postgresql.org/docs/current/libpq-envars.html
Related Topics
How to Make Fork Changes Reflect with The Master When Updated
How to Change Port Gitlab on Centos 6
Source Bashrc Doesn't Work in Cron
How to Store Data Permanently in /Tmp Directory in Linux
User Time Larger Than Real Time
How to Find List of Valid Locales in My Linux Using Perl
Copying Files with Wildcard (*) to a Folder in a Bash Script - Why Isn't It Working
Why Can't Bash Recognize The Existence of a Socket File
How to Send Email from The Command Line
Raspberry-Pi Docker Error: Standard_Init_Linux.Go:178: Exec User Process Caused "Exec Format Error"
Running Docker Without Sudo on Ubuntu 14.04
How to Find All Immediate Sub-Directories of The Current Directory on Linux
Proxmox with Opnsense as Firewall/Gw - Routing Issue
Docker Rootless Unable to Pull Images
Find' (Command) Finds Nothing with -Wholename