How to edit sshd_config remotely? A problem of incorrect permissions?
I am trying to remotely edit sshd_config file using WinSCP and putty. Unfortunately, I keep getting the following error-
“Cannot overwrite remote file Press delete to delete the file and create a new one”.
I tried deleting, but I got a similar error. I also tried changing the permissions on the file, but I got the error -
cannot change properties of file sshd_config.
I suspect I don't have the correct permissions, but I'm not sure what to do. I've attached a pic of my permissions below.
QUESTION
What do I need to do to be able to overwrite sshd_config ? Is it to do with my current permissions?
2 Answers
Editing config files on Windows and transfering them back to Linux is dangerous because Windows uses different line breaks than Linux.
You should rather edit the file directly on the remote machine by typing sudo nano /etc/ssh/sshd_config make your changes and press CTRL+O to save and CTRL+X to exit. This way you also don't have to care about permissions cause you are already root.
The answer actually turned out to be pretty obvious. I'm new to linux, so I was confused. When I logged into the server using the username and pw that I used to install the server, I was under the misunderstanding that this was the same as being root.
Anyway, I didn't have the correct permissions to edit the file, so to fix it I used Putty to ssh into the server then I created a new group called editors with the following code
sudo addgroup editors then I added my user to that group
sudo adduser myusername editorsNext I gave the group editors ownership of the directory
sudo chown :editors /etc/ssh/Next I changed the file permissions such that the group could write to the folder
sudo chmod 770 /etc/sshAfter logging back into the server again with WinSCP I was able to edit the files in the directory.
This may not be the recommended way of going about this- if it isn't I'd appreciate someone letting me know :)