I have a weird problem that is becoming rather annoying as I can't reason out why my edits to /etc/hosts file doesn't save. When I edit with sudo permissions and save them it looks fine. As soon as I open a new terminal or quit a terminal and check again the edits I made are gone.
sudo vim /etc/hosts/ or sudo vim /private/etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
and I try to add this line: 127.0.0.1 ac-decountsv.example.com
I also tried editing the /private/etc/hosts/. Could some one tell me what am I overlooking?
Thanks
OS X has a lock on changes to system files; remove the lock & make your changes.
This may help:
https://superuser.com/questions/40749/command-to-unlock-locked-files-on-os-x
you can edit the file by using the below
chattr -i /etc/hosts; vi /etc/hosts; chattr +i /etc/hosts
Related
UPDATE:
I moved my question to ask ubuntu community, but can not delete it from here... if you have an awenser, please share it on ubuntu community not here... Thanks
i want to make an change on a file but i cant do that because i have not correct permissions:
➜ ls -l pycharm64.vmoptions
-rw-r--r-- 1 root root 427 Dec 28 18:33 pycharm64.vmoptions
i tried to change permisions by these two command:
sudo chmod a+w pycharm64.vmoptions
and
sudo chown user:user pycharm64.vmoptions
but in i get an erro both time:
Read-only file system
how can i make an change on my file? (honestly i dont care about the owner and groups of the file... i just want to change my file anyway)
P.S: my OS is UBUNTU
You can change a file on read only by setting the "immutable property"
chattr +i [fileName]
If you want to revert it just change the "+" for a "-"
chattr -i [fileName]
Your filesystem could be mounted as read only. You have to change first before you can write anything to it. Changing file permissions also requires writing on the filesystem.
You may be able to mount it as read write with command like:
sudo mount -o remount,rw /dev/foo /mount/destination/dir
In this command you spesify that you want to remount the filesystem with different options, adding the readwrite, rw capability.
If you successd in changing the filesystem to read write, then you should be able to change to file permissions with the commands you tried earlier.
You can`t edit it directly (I'm not sure about Windows).
You should edit custom settings file instead:
Manually
nano ~/.config/JetBrains/PyCharm2022.3/pycharm64.vmoptions
or from IDE -- https://intellij-support.jetbrains.com/hc/en-us/articles/206544869.
I am often having difficulties to set up password-less ssh connection on my clusters.
So I wrote a script, I thought it was working on ubuntu 14.04. I tried it today on a ubuntu 15 cluster, and it didn't work.
I am not really sure then if it ever worked on ubuntu 14.4 :-/
It is based on this page : http://mah.everybody.org/docs/ssh
I put the code on this github : https://github.com/romainjouin/formation_spark/blob/master/ubuntu_excange_ssh_keys.sh
the idea is to call the script, passing as first parameter the user#ip where we want to set up a password less ssh connection.
Can someone have a look to the github script : is there an obvious thing I am missing ?
Furthermore, before launching the script I :
Change /etc/ssh/sshd_config to uncomment
AuthorizedKeysFile %h/.ssh/authorized_keys
ant then do :
$/etc/init.d/ssh restart
EDIT
The code seems to work fine, but I was missing the authorisation on the home directory to make it work (home dir was 777 instead of 700).
The code seems to work fine, but I was missing the authorisation on the home directory to make it work (home dir was 777 instead of 700). – Romain Jouin
suppose you ssh remote-user#remote-host frequently, first
ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host
then, edit you ~/.ssh/config file
cat ~./ssh/config
Host foobar
HostName remote-host-ip
Port 22
User remote-user
IdentityFile ~/.ssh/id_rsa
now you can ssh like this
ssh foobar
When I sudo to root vi mode is turned off, so that I need to either run set -o vi or change root's profile to use vi mode. I don't want to change the profile as this will impact other engineers and I don't want to have to type set -o vi every time I sudo. I read man sudo and tried sudo -i and sudo -sE, but neither of these preserved $SHELLOPTS where vi mode is set.
I did find that setting env_keep += SHELLOPTS in /etc/sudoers fixed the issue, but this file is being maintained by a config mgmt system and I don't want to make such a global change just because I prefer vi as my command line editor. So, ultimately is there a way I can set this when sudoing that will not require making changes to shared and/or managed config files?
[user#host:~]$ echo $SHELLOPTS
braceexpand:hashall:histexpand:history:interactive-comments:monitor:vi
[user#host:~]$ sudo -i
[root#host:~]# echo $SHELLOPTS
braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
[user#host:~]$ sudo -sE
[root#host:~]# echo $SHELLOPTS
braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
For work, I have to connect to dozens of Linux machines via SSH (to perform maintenance, monitor the system, install software, etc).
I have a small arsenal of scripts that help me do some of these tasks, and these are located in a folder on my Mac in /Users/me/bin. I want to be able to run these scripts on the remote Linux machine, but for several reasons I do not want these scripts permanently located on these machines (e.g., other people also connect to these remote machines, and it would be unwise to let them execute these files).
So, is possible to share scripts across an SSH connection for the lifetime of the session only?
I have a couple of ideas on how to do this, but I don't know if any of them will work. Firstly, if SSH allows file mounting, I could automatically mount me#mymac:/Users/me/bin to me#linux:/remote_bin when I connect to the remote Linux box, and set my PATH variable to "$PATH:/remote_bin". Secondly, I could set up port forwarding in the connection string (e.g., ssh me#linux -R 9999:127.0.0.1:<SMBPORT|ETC> and every time I connect mount the share and set the $PATH variable.
EDIT: I've come up with a semi-solution. On the linux machine, edit /etc/ssh/sshd_config to add the following subsystem: Subsystem shareduserbinary sudo su -l -c "/bin/mount -t cifs -o port=9999,username=me,nounix,sec=ntlmssp //127.0.0.1/exported_bin /mnt/remote_bin" && bash -l -i -s. When connecting to the remote machine, set up a reverse port forward and invoke the subsystem. E.g.: ssh -R 9999:127.0.0.1:445 -s shareduserbinary me#linux.
EDIT 2: You can make the solution above cleaner, by removing the -l from the sudo command and changing the path from /mnt/remote_bin to $HOME/rbin.
Interesting question. Perhaps you can add a command to ~/.bash_login (assuming you are using bash) to copy the scripts from a remote host (such as your mac) when you login, then add a command to ~/.bash_logout to delete the scripts when you logout. But, as bmargulies points out, it would be a good idea to go a step further and make sure that nobody else has permissions to read or execute the scripts.
You can use OpenSSH's LocalCommand to upload the files (using e.g. scp or rsync) when initiating an SSH session (see man ssh_config and this):
Host server1 server2 [...]
PermitLocalCommand yes
LocalCommand scp -q /Users/bin/me/* %h:temp_bin/
and use .bash_logout or an EXIT-trap that you specify in your .bashrc to delete the contents of the directory on logout.
I want to create a shell script that can change the hostname of my Ubuntu permanently. Whenever I use the hostname New_hostname command, it returns to the original hostname after I restart the machine.
I found out that the only way I can change this permanently is by modifying the file in /etc/hostname and save it. Is there some way I can do this using a shell script only? I also have a password.
The hostnamectl combines setting the hostname via the hostname command and editing /etc/hostname. Unfortunately, editing /etc/hosts still has to be done separately.
hostnamectl set-hostname <new-hostname>
Type
echo "myNewHostName" > /etc/hostname
in any shell with root access near you..
You may also want to take a look at the file /etc/hosts, cf. http://pricklytech.wordpress.com/2013/04/24/ubuntu-change-hostname-permanently-using-the-command-line/.
In Ubuntu 18.04 LTS
Hostname changing via SSH is reverted after reboot in Ubuntu 18.04. Make permanent change as following way.
1. Edit /etc/cloud/cloud.cfg
sudo nano /etc/cloud/cloud.cfg
Set preserve_hostname to true
preserve_hostname: true
2. Run hostnamectl
hostnamectl set-hostname new-host-name
3. Reboot
sudo reboot
Change hostname permanently without reboot
/etc/hosts
127.0.0.1 persistent_host_name
/etc/hostname
persistent_host_name
Apply changes Immediately
$ sudo hostname persistent_host_name
Check changes
$ hostname
persistent_host_name
Typically, you would need to change it in these files:
/etc/hostname
/etc/hosts
If you are using some advanced printers, also here:
/etc/printcap
This is why I would recommend doing it manually - but search the old hostnames first. To find all occurrences in /etc:
sudo grep -iRI "_OLDHOSTNAME_" /etc 2>/dev/null
Then change the _OLDHOSTNAME_ in every occurrence.
Done.
To chaneg the Hostname permanet in ubuntu machine
Go to :
#vim /etc/hostname
Type the hostname inside the file you want to set for the machine
Then save and the file
After saving the document run this command
# hostname -F /etc/hostname
Then edit the /etc/hosts file
#vim /etc/hosts
type the ip hostname inside the file
Then Logout of of the machine and relogin into the machine
If you just want to change host name, because its getting displayed as a command prompt in the terminal. Then you can replace \h in PS1 with "desired_host_name" in ~/.bashrc
Like in ~/.bashrc put this line at end of file:
export PS2="continue-> ";
export PS1="\u#3050:~$ ";
Change Hostname on Ubuntu 18.04
Definition
A hostname is a label that identifies a machine on the network. You shouldn’t use the same hostname on two different machines on a same network.
Prerequisites
User should have a sudo privileges
Change the Hostname
Change the hostname using hostnamectl command. If you want to change the hostname to new_hostname
sudo hostnamectl set-hostname new_hostname
It will not change the hostname directly. You want to preserve the changes permanently then you have to edit cloud.cfg file
sudo nano /etc/cloud/cloud.cfg
# This will cause the set+update hostname module to not operate (if true)
preserve_hostname: true
Save the file and close your editor.
Verify your Changes
You can verify your changes using command hostnamectl it will show new_hostname under Static hostname
PS: Source Link