Connecting to a Remote Server with SSH
February 05, 2020
OUTLINE:
- Connecting to a server via ssh
- Navigating the user directory
- Creating directories and files
- Writing and reading to files
NOTE: the $ indicates the use of the command line. Do not copy the $ while typing commands.
1.
First things first we need to connect to the remote server. To get started, in a command line (terminal for linux/mac, cmd/powershell for windows).
$ ssh username@ip.addressEnter password to connect.
2.
Now we’re connected to the server, it is useful to get acquainted with traversing directories. Here are some basic commands to get started. Print working dircetory:
$ pwdList all files in current directory verbosely:
$ ls -alChange directory to ~ (home directory):
$ cd ~Now we’re at the home directory and ready to get started file creation.
3.
A necessary function is to make new folders to create file structures and organization. To make and relocate to a new directory:
$ mkdir test$ cd testNow we make a new file:
$ touch hello.txt$ ls -alWith that list all command we can see that there is a new file in our test directory.
4.
To access and edit that file with a text editor we can use nano:
$ nano hello.txtTry to write something in nano, it doesn’t matter what for now.
Once you’re done, do ^O ^X to save and exit.
$ ls -alTo read back the contents of what you just wrote in hello.txt we can use cat:
$ cat hello.txtNow say we aren’t happy with the contents of hello.txt. We can append a new line to the file using the >> operator.
$ echo "Hello" >> hello.txt$ cat hello.txt