Solutions to IT problems

Solutions I found when learning new IT stuff

Connect to Ubuntu from Windows using SSH

with one comment


Intro

If you have read my previous post  you know I had some troubles getting files from Windows to Ubuntu. This was caused by the fact that internet access was blocked by a proxy and I could not use apt-get to install openssh server. Well since this works now, let’s start.

Install OpenSSH Server

In Ubuntu run following command:
sudo apt-get install openssh-server

For further information and configuration please see this. We will continue with the default configuration.

Install WinSCP and PuTTY

  1. Download WinSCP and PuTTY.
  2. Install WinSCP
  3. Move the downloaded putty.exe to your desired folder.
  4. Copy that folder path.
  5. Run WinSCP and on the left menu click on Preferences
  6. Click on the Preferences button
  7. Go to Integration -> Applications
  8. Paste the Path to putty.exe in the according text field and click ok.

Connect to Ubuntu

In WinSCP left-side menu go to Session, select SFTP as file protocol, the Ubuntu Servers IP Address in host name, and the user name and password of a valid Ubuntu user. Then click on “Login”. You should now be connected to the Ubuntu Server and you should be able to easily transfer files between the 2 Computers.

If you want to execute terminal commands, I suggest to use PuTTY either directly by running putty.exe or in WinSCP go to Commands -> Open in PuTTY.

Increased Security

For better security you may choose to use Public key authentication. Follow this guide to set it up and then this guide to simplify future usage.

WinSCP and sudo

Sometimes it can be handy to edit config files through WinSCP and hence your desired editor. To enable file transfer and editing of files with root privileges,  do the following in Ubuntu:

  1. connect to ubuntu terminal with PuTTY
  2. cd /etc/sudoers.d
  3. create new file: sudo vi NoPWForSftp (you may choose a different file name)
  4. add yourUserName ALL=NOPASSWD: /usr/lib/openssh/sftp-server to this file
  5. save file and exit from vi (:w and then :q)
  6. change file permissions to 0440 (r–r—–):
  7. chmod o-r NoPWForSftp removes read privilege for “other” (see Ubuntu Help for further info)
  8. chmod ugo-w NoPWForSftp removes write privilege for everyone
  9. check privilege: ls -l

Now switch to Windows and in WinSCP do the following:

  1. Check “Advanced Options”
  2. If you have a stored session edit it by clicking on “Edit” at the right side of the WinSCP Window
  3. In Environment->SFTP in SFTP server text box enter sudo /usr/lib/openssh/sftp-server
  4. Click “Save” and then try to log in


You should now be able to edit files in Windows in your favorite editor. I suggest to be cautious with this and always create a copy before editing.

Advertisements

Written by kienerj

October 27, 2011 at 10:34

Posted in Linux, Operating Systems, Tools, Windows

Tagged with ,

One Response

Subscribe to comments with RSS.

  1. I LOVE YOU!!!! Thank you so much. This is the only guide which explains things in plain english and actually accomplishes what i want to get done. Thanks!!!!!!

    Andrew Ialacci

    March 26, 2012 at 19:27


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: