Linux ssh open file

Open file in local text editor from within an SSH connection

I’m not a vim guy. I’d like to be able to open log files in Sublime Text when in an SSH connection from within Terminal. Is there a way I could do this? I’m thinking there must be a command or something that could copy the file over to a temporary directory in OS X and then open it in Sublime Text, and when I save it, it’ll copy back to the original location through SSH; similar to how FileZilla does it. I’m on Mac OS X MT. The server I SSH into is running Ubuntu. I’m using Terminal.

3 Answers 3

You might be interested in sshfs. With that package you can mount a remote directory via SSH and use it like a local one:

sshfs user@ubuntu:/var/log /mnt/ubuntu_logs 

It works completely transparent and you can use in principle every program which is installed on your local machine.

In order to use sshfs you’ll need also a package that provides a Filesystem in Userspace, on OSX it’s obviously called OSXFUSE (http://osxfuse.github.com).

You’ll find some more information at that answer on SO and the installation procedure seems to be rather standard as two dmg packages are provided at the above linked Github site.

Use sshfs . that way you can access the files on the remote machine as if they were local, in other words using the apps you have locally installed on your Mac.

I have successfully installed it on Snowleopard in the past.

You can try something that I’ve been working on called ‘xeno’. It will allow you to open up files/folders in your local editor from within an SSH connection into any editor on your local machine (and automatically synchronize changes to the remote machine). It should work on almost all POSIX systems (I myself use it from OS X to connect to Linux machines and edit files in Sublime Text). It’s free and open source. I’d love some feedback.

Читайте также:  Configuring ip address in linux

Basically, it’s a Git/SSH mashup written in Python that allows you to edit files and folders on a remote machine in your local editor. You don’t have to configure kernel modules, you don’t need to have a persistent connection, it’s all automatic, and it won’t interfere with existing source control because it uses an out-of-worktree Git repository. Because it’s built on Git, it’s also extremely fast and supports automatic merging of files that might be changing on both ends, unlike SSHFS which will just clobber any files with older timestamps.

You must log in to answer this question.

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Open file from remote computer on host computer

I’m trying to edit a file from a remote computer connected via ssh. How can I open the remote file on my local computer to edit?

6 Answers 6

You can mount the remote directory with sshfs , after that, the file is accessible in your local directory tree.

sshfs user@domain:/remote/directory/ /local/directory/ 

Or just copy the file over with scp/rsync , edit it, and copy it back.

When I try the ‘sshfs’ command it throws a «missing host» error. Any way around that? This is what I’m trying to do: sshfs USER@IP_ADDRESS//~/folder/folder_here/another_folder/file.txt Note: I didn’t use a port number if that matters.

@masterninja01 You need to specify a local mount point; also, you can’t mount the actual file, you would mount the directory (also: the source address needs to include a colon) so: sshfs USER@IP_ADDRESS:~/folder/ ~/folder . ~/folder needs to exist locally.

sshfs -o IdentityFile=~/.ssh/keyname user@domain:/some/remote/dir/ /my/local/dir/ sshfs ssh key parameter is different from ssh parm

If you are familiar with vim, you may use it as follows:

vim scp://user@host:port/file_path_and_filename 

Make sure not to forget the «/» character before the filepath; otherwise it won’t work; for example:

vim scp://user@192.168.1.4:2243//home/user/my_file 

You can skip the portnumber if is the same of the default on your /etc/ssh/sshd_config file

Читайте также:  Rocky linux vs centos

@dgsleeps What part of the /etc/ssh/sshd_config do you check for the port? I have a couple of ports in my file.

  • open file manager
  • press Ctrl+L to focus address bar
  • enter sftp://host/ and press Enter (replace «host» with your target host)

The file system of the remote host will be displayed in file manager now, and you can navigate to your target directory and double-click the file to open it. As far as I know you can now use any local program to open the file (it doesn’t have to be a Gnome or KDE application).

You should also be able to set a bookmark to the remote target directory, to quickly get there again later.

If you want to connect as a different user or using a different port, you can use sftp://user@host:port/somedirectory/ .

Источник

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.

    Источник

    Оцените статью
    Adblock
    detector