# Windows Help

This page has some help on random tasks that you may need in Windows.

# Terminal

Terminal or PowerShell is a command-line shell included with Windows. You can open it in any folder with these steps:

  • Right-click the folder.
  • From the menu, choose Open in Terminal.

In the terminal you may see a message to install the latest version of PowerShell. You can install PowerShell in the Microsoft Store and enable it as your default terminal:

  • Open Terminal.
  • Click the downward arrow in the title bar and choose Settings.
  • In the Startup panel, at Default profile, select PowerShell.
  • Click Save.

# SSH connection

You use SSH connections to connect to your server or remote host from your workstation. You can open a terminal at the remote host to enter commands, you can download or upload files, and you can use services at private ports using SSH tunnels.

You can do all these things directly in the Windows Terminal, but if you need to connect more often, it’s easier if you set up a dedicated client first.

For an SSH connection you need:

  • The host name or IP address of your server.
  • The username and the private key or password of a user.

If you only have a password, we suggest to create a private key for extra security. Some SSH servers do not even allow logins with a password.

# Set up PuTTY

PuTTY is an SSH client for Windows that allows you to open a terminal and SSH tunnels to your server. We will set up PuTTY here to create the first SSH connection.

Create a session in PuTTY:

  • Start PuTTY.
  • On the left, select Session.
  • Under Host Name (or IP address), enter the host name or IP address of your server.
  • Under Saved Sessions type a name for your server.
  • Click Save.
  • You may set some preferences in the left-hand side bar, such as the terminal window size and colours. Then save your session under Saved Sessions again.

If you have a private key, you need to configure it next. If you only have a password, you can skip this. Private keys come in different formats. You may have a .ppk file for PuTTY or an OpenSSH file. If you have an OpenSSH file, you need to convert it to a .ppk file first:

  • Start PuTTYgen.
  • From the menu, choose Conversions > Import key.
  • Click Save private key and save the .ppk file. It’s important to keep your private keys in a safe location.

Then select the .ppk file in PuTTY.

  • On the left, select Connection > SSH > Auth > Credentials.
  • At Private key file for authentication, open your .ppk file.
  • On the left, select Session.
  • Save your session again with Save.

Now you are ready to make your first connection:

  • Double-click your server under Saved Sessions.
  • The first time you need to indicate that you trust the host. Click Accept.
  • If you use a private key, you can just enter your username. Otherwise enter your username and password.

If you are installing an Ubuntu server and you just logged in with the initial ubuntu or root user, you should go back to the Ubuntu installation and create a normal user now.

# Set up a private key

If you are logging in with a password, we recommend to set up a private key instead. You can also use these instructions to set up a new private key, for example for another workstation. First we create a private / public key pair.

  • Open Terminal on your computer and enter this command:
    > ssh-keygen
    
  • When asked for the file location and passphrase, just press Enter.
  • You should now have two files at the shown location (directory .ssh in your home directory):
    • id_rsa: your private key
    • id_rsa.pub: your public key
  • Copy the files to a safe location so you can restore them if needed.

Upload the public key to your server.

  • Still in the terminal on your computer, if you only have a password, then enter this command:
    > scp .ssh\id_rsa.pub <USERNAME>@<HOSTNAME>:~
    
    If you have another private key, for example from another workstation, then enter this command:
    > scp -i path\to\private_key .ssh\id_rsa.pub <USERNAME>@<HOSTNAME>:~
    
    This only works if your private key is in a secure location that only you can access, such as inside your home directory.
  • The first time you need to indicate that you trust the host. Enter “yes”.
  • Enter your password if needed.
  • Now the public key is at your server.

Now we will open a terminal to your server.

  • In the terminal on your computer, if you only have a password, enter:
    > ssh <USERNAME>@<HOSTNAME>
    
    If you have another private key, enter:
    > ssh -i path\to\private_key <USERNAME>@<HOSTNAME>
    
  • Enter these commands:
    $ mkdir -p .ssh
    $ cat id_rsa.pub >> .ssh/authorized_keys
    $ rm id_rsa.pub
    
  • Close the connection with exit.

Then we set up PuTTY to use the private key. First we need to convert your private key from SSH format to PuTTY format.

  • Start PuTTYgen.
  • From the menu, choose Conversions > Import key.
  • Open your private key id_rsa.
  • Click Save private key.
  • Save it as id_rsa.ppk.

Finally we load the key in PuTTY.

  • Start PuTTY.
  • On the left, select Session.
  • Under Saved Sessions, select your server.
  • Click Load.
  • On the left, select Connection > SSH > Auth > Credentials.
  • At Private key file for authentication, open your file id_rsa.ppk.
  • On the left, select Session.
  • Save your session again with Save.

# Open terminal

If you have set up PuTTY, you can open a terminal to your server any time with these steps:

  • Start PuTTY.
  • On the left, select Session.
  • Double-click your server under Saved Sessions.
  • Enter your username.
  • If you did not set up a private key, you need to enter your password as well.

You can also open a connection directly in Windows Terminal:

  • Open Terminal on your computer.
  • Enter this command:
    > ssh <USERNAME>@<HOSTNAME>
    
    Or if your private key is not at ~\.ssh\id_rsa:
    > ssh -i path\to\private_key <USERNAME>@<HOSTNAME>
    
    This only works if your private key is in a secure location that only you can access, such as inside your home directory.
  • If you don’t have a private key, enter your password.

# Set up FileZilla

FileZilla is a client for Windows that allows you to download or upload files over an SSH connection.

  • Download the FileZilla Client:
    https://filezilla-project.org/ (opens new window)
  • The installer includes sponsored software. When you are asked to install it, choose Decline. For the rest just accept the defaults.
  • Start FileZilla.
  • Open the Site Manager using the icon on the left in the toolbar. Or choose File > Site Manager... from the menu.
  • Click New site.
  • Enter a name for your server.
  • Go to the General tab on the right.
  • At Protocol, select SFTP.
  • At Host, enter the host name or IP address of your server.
  • At Logon Type, select Key file if you have a private key, or Ask for password if you only have a password.
  • At User, enter your username.
  • If you have a private key, at Key file open your file id_rsa.ppk.
  • Click OK.
  • If you are asked whether FileZilla should remember passwords, choose Do not save passwords.

# Download or upload files

If you have set up FileZilla, you can download and upload with these steps:

  • Start FileZilla.
  • Connect to your server through the Site Manager, or using the drop-down arrow next to the icon on the left in the toolbar.
  • You see the files on your computer on the left, and the files on the server on the right. You can upload or download by double-clicking, right-clicking or dragging files.

You can also download and upload directly in Windows Terminal.

  • Open Terminal on your computer in the directory to which you want to download files, or from which you want to upload files.
  • Upload a file with this command:
    > scp myfile.txt <USERNAME>@<HOSTNAME>:/path/to/remote-dir
    
    Or if your private key is not at ~\.ssh\id_rsa:
    > scp -i path\to\private_key myfile.txt <USERNAME>@<HOSTNAME>:/path/to/remote-dir
    
  • Download a file with this command:
    > scp <USERNAME>@<HOSTNAME>:/path/to/remote-dir/myfile.txt .
    
  • For uploading to the remote home directory, use path ~:
    > scp myfile.txt <USERNAME>@<HOSTNAME>:~
    

# SSH tunnel

An SSH tunnel allows you to access a port on a server that is otherwise not accessible outside the server because it is blocked by a firewall. You commonly use an SSH tunnel to access private development or administration services. The SSH tunnel maps a local port on your workstation to a destination that is accessible from the server. Then you can access it on localhost at your workstation.

For example you can map local port 28080 to remote destination localhost:8080. Here localhost is from the perspective of the server, and you could also use another hostname that is accessible from inside the server. When you have set it up, you can access localhost:28080 from your workstation and it will be the same as accessing localhost:8080 from inside the server.

If you have set up PuTTY, you can configure SSH tunnels there.

  • Start PuTTY.
  • On the left, select Session.
  • Under Saved Sessions, select your server.
  • Click Load.
  • On the left, select Connection > SSH > Tunnels.
  • At Source port enter the local port. This can be the same as the remote port or a different port. For example 28080.
  • At Destination enter the remote destination like localhost:8080.
  • Click Add.
  • On the left, select Session.
  • Click Save to save the SSH tunnel in the session.
  • Connect to your server. The SSH tunnel is now effective and you can connect to localhost:28080 on your workstation.

From now on, every time you connect to the server, the SSH tunnel is effective automatically.

You can also open an SSH tunnel directly in Windows Terminal.

  • Open Terminal on your computer.
  • Following our example above, enter this command:
    $ ssh -L 28080:localhost:8080 <USERNAME>@<HOSTNAME>
    
    Here the local port is 28080 and the remote destination is localhost:8080.
  • If your private key is not at ~\.ssh\id_rsa, then enter:
    > ssh -i path\to\private_key -L 28080:localhost:8080 <USERNAME>@<HOSTNAME>
    

# Add to Path

Some programs need to be in your Windows “Path”, so they can be run from any working directory. You can add the directory where the program is located with these steps:

  • From the Start menu, open View advanced system settings.
  • Open the tab Advanced.
  • Click the button Environment Variables...
  • Select the variable “Path” under User variables (so you can access the program from anywhere) or under System variables (so the system and any user can access it). If the variable doesn’t exist, you can just create it.
  • Click Edit....
  • Add the desired directory to the list.

# Executable files in Git

Some files need to be executable in Linux or macOS, in particular shell scripts such as gradlew. The Windows file system does not have the executable attribute, but you can make files executable in Git from Windows, so that Linux and Mac users can run them.

  • Open Terminal in the directory with the file that you want to make executable.
  • Enter these commands (fill in your filename):
    > git update-index --chmod=+x filename
    > git commit -m "Made filename executable"