Edit file in linux ssh

Edit-text-files-over-SSH using a local text editor

The word is archaic, and they’re not. Both Vim & Emacs can easily edit a remote file using builtin commands.

@MikkoOhtamaa: your workflow is unclear: the server side tells your local editor that the server wants you to edit a file?

Calling vim and emacs archaic and wanting to use a gui text editor over ssh is a rant, not a question.

5 Answers 5

You can use rsub and rmate to edit remote files in your local Sublime Text over ssh.

  • install the rsub package in Sublime Text (with Package Manager)
  • forward port 52698 via ssh, use ssh -R 52698:localhost:52698 . or set your config
    • create/edit ~/.ssh/config and chmod 600 ~/.ssh/config (to avoid a permissions problem)
    • add (replace SERVERNAME with your server, you can also use * ):
    Host SERVERNAME RemoteForward 52698 127.0.0.1:52698 
    sudo wget -O /usr/local/bin/rsub https://raw.github.com/aurora/rmate/master/rmate sudo chmod +x /usr/local/bin/rsub 

    Then you can do rsub file in the ssh session and it will open file in your local ST editor.

    Works with ST2/ST3 and you can also sudo rsub file !

    This is an old question, but without a clear answer yet. However, you do not mention from which desktop environment you want to edit from? At one point you mention WinSCP; clearly Windows, on the other hand Cyberduck is a Mac program.

    Assuming you work from a Mac; the venerable BBEdit, while not as ‘sexy’ as Sublime and before that TextMate, still has some features up its sleeve that the other editors don’t have.

    Like opening and writing files directly from and to ssh and ftp servers, from within the program. I’ve used this functionality since version 5 or so, which is now 13 years ago. Multiple lifetimes ago, and still not available in ‘modern’ editors.

    Источник

    HOW TO EDIT AND SAVE A FILE IN PUTTY? [EASY GUIDE] ☑️

    PuTTY is a free open-source software to connect with Linux using SSH or Telnet. PuTTY is an SSH and Telnet Client software used to establish an encrypted connection from one server to another.

    File modification in Linux via PuTTY is fairly easy. You can easily Edit & Save any file in PuTTY by using the vi & :wq! command in which, the vi command is used to edit the file, and then :wq! command is used to save the edited file and exit from the editing section.

    edit file in putty

    Today in this documentation you will learn how to Edit and Save a file using PuTTy. Suppose you want to edit a file whose location is /home/root/public_html/etc/hosts where etc is a directory and hosts is a file, then how to edit hosts file using PuTTy.

    Let us quickly watch this video to easily learn how to Edit and Save a file using PuTTy.

    Let’s make it as simple as it is.

    How To Edit and Save a file in PuTTY (In Short) :

    Use the cd path/to/directory command to move inside the directory.

    Use vi filename.exe command to enter in the editing mode.

    Press the i button from the keyboard to start the editing.

    Press the Esc button to stop the editing.

    Type :wq! to Save the file & Close the editing window.

    How To Edit and Save a file in PuTTY ( In Detail) :

    • Log in to PuTTY & navigate to the directory where you want to perform the task. Use the cd path/to/directory command to browse the directories.
    • Find the file you want to edit by using the file filename.extension command.
    • Now use the vi filename.exe command to enter inside the editing zone.
    • To edit the file, type i from your keyboard.
    • Once the editing is done, type the Esc button from your keyboard and then type :wq! command, hit the enter button to Save the file and Close the editing tab.
    • That’s it. You’ve successfully edited & saved the file in PuTTY. You can use the cat filename.exe command to view the contents inside a file.

    That’s how you can easily View, Edit, and Save a file using PuTTY. For more assistance, you can visit RedserverHost.Com as there are numerous articles related to Linux commands, Web Hostings, WordPress, Websites, and many more.

    This is how you Edit and Save files using PuTTy.

    If you enjoyed this tutorial, please consider following us on Facebook and Twitter.

    If you have any queries, feel free to let us know via the comments section below.

    Источник

    How to Edit & Create a File in SSH Using Nano

    Learn How to Edit & Create a File in SSH Using Nano

    If you are using the linux command line, there are several programs for you to use to edit files in SSH. This is a convenient way to modify files since you can quickly change them in terminal without using a separate text editor.

    Here at InMotion Hosting, our System Administration team primarily uses programs called nano and vi. Vi is a very sophisticated program with somewhat of a high learning curve. Because of this, we’re going to show you how to edit files using the nano SSH editor. The nano editor should be included with all major versions of Linux and Unix.

    Create a File in SSH

    1. Open a terminal or connect to your server vis SSH.
    2. Use the cd command to change to the directory you want to create the file in. In this example, I’m creating a file in the public_html folder.

    Creating a File via SSH with Nano

  • The nano editor will then open up the file and you can begin entering text.
  • Once you have finished editing click Ctrl+O then the Enter key to save and create the file.
  • Edit File in SSH

    In this section, we’ll walk you through the process of editing a file via SSH using nano.

    1. When editing files with nano, the first thing you’ll need to do is connect to your server via SSH.
    2. We’re currently logged in, so let’s run “pwd” command to see what directory we’re in

    Edit File in SSH - pwd


    Now we’ll run the “ls” command to see what files are in this directory.

    Edit File in SSH - ls Command


    As you can see, we’re in the testa folder and there are currently three files: file1.txt, file2.txt, and file3.txt. If we wanted to edit file2.txt using nano, enter the following command:

    Editing a File in Nano

    After running this command, the nano file editor will open and load the contents of file2.txt.

    Top of the Nano Editor

    What you’re looking at above is me editing a file using nano. The top line shows the version of nano you’re using and the name of the file you’re editing.

    Bottom of the Nano Editor

    The bottom part of the screen includes all of the commands that you can run.
    You can then run the ls command to view the new file.

    View of the Cursor in Nano

    You can move the cursor around with your keyboard arrows, but the mouse will not work in the nano editor. Here I am deleting a line of text in the file.

    So what do you do now? Start editing the file! You can edit the file as you would using any other editor, except you don’t have the option to use your mouse to point and click on items.

    How to Save & Exit Nano

    The commands at the bottom of the nano page are executed by holding down Ctrl on your keyboard followed by the letter listed. Here are the steps for saving a file and exiting the nano editor.

    Save File in Nano

    Exit Nano

    • When you’re ready to exit nano, hold Ctrl + X and you will be exited from the application.

    Congratulations, now you know how to edit a file in SSH using nano, as well as how to save and exit. Check out our Server section for more helpful tutorials to help you manage your environment.

    No matter if you’re a developer, system administrator, or simply a fan of SSH and command line, InMotion’s Cloud VPS plans provide a fast, scalable environment that is budget-friendly.

    John-Paul is an Electronics Engineer that spent most of his career in IT. He has been a Technical Writer for InMotion since 2013.

    Источник

    How to Create and Edit a File via SSH?

    You can create and edit a file when logged into a MilesWeb server via SSH. This article explains the use of two text editors:

    nano — Best for beginners.
    vim — Offers more features than ‘nano’, but also difficult to use. It is a good choice for advanced users.

    Note: If you don’t want to edit files in a terminal, you can check the below article:

    Create and Edit a File Using ‘nano’

    ‘nano’ is the best choice for newbies as it is easier to use than ‘vim’. Check the steps below to create and edit a file using ‘nano’.

    1. Log into your server using SSH.

    2. Go to the directory location where you want to create the file, or edit an existing file.

    3. Type nano along with the name of the file. For example, if you want to create (or edit) a new file named as index.html, run the following:

    You will see a new file open with the name index.html as below:

    4. Now, you can type your data into the file.

    5. After you complete typing the data, save the file and hold down the Ctrl key and press the letter ‘O’ (Ctrl + O).

    You will be prompted to confirm the file name that is already set as ‘index.html’ as below:

    6. Next, click the ‘Enter’ key on your keyboard for saving the file.

    7. Then, click Ctrl + X to close ‘nano’ and go back to your shell.

    Create and Edit a File Using ‘vim’

    1. Log into your server using SSH.

    2. Go to the directory location where you want to create the file, or edit an existing file.

    3. Type in vim along with the name of the file. For example, if you want to create (or edit) a new file named as test.html, run the following:

    The ‘vim’ editor will get displayed which might seem to be confusing at first as you won’t be able to type into the file yet:

    4. On the keyboard, click the letter ‘i’ to enter INSERT mode in ‘vim’.

    You will now see — INSERT — on the bottom left:

    5. Type the data into the file now.

    6. After you are done with editing the file, click the ESC key. You will be taken out of INSERT mode and — INSERT — will get disappeared from the bottom left of your terminal.

    7. Save the file by typing in a colon followed by wq as below:

    You will see :wq appeared on the bottom left:

    8. Now, on your keyboard click the ‘Enter’ key to save.

    Changing the Name of a File

    If you wish to change the name of a file, use the mv command. For example, a file named ‘file1.txt’ changes to ‘file2.txt’.

    [server]$ mv file1.txt file2.txt

    That’s it! You can now create and edit a file via SSH.

    Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.

    Источник

    Читайте также:  Linux start shell script
Оцените статью
Adblock
detector