Ubuntu server commands

Here is a collection of commands relevant to using a remote server that I find helpful.

Establish connection

ssh -X -p *port* user_name@server_ip ssh command establishes a ssh connection with the server. -X opens an X-server, which allows you to open GUI software (e.g. firefox) on the server and convey the display to your local computer -p selects the specific port the connection is going to be established. Not all ports of a computer are always open for security reasons. This along the user name and the server’s IP should be provided by the server admin.

ssh-copy-id -i ~/.ssh/id_rsa.pub {remote-host} can save the password to ssh agent to avoid keep typing the password.

Note, it is important to understand the security of using keys and it is recommended not to use the same public-private key pair for all the usage. Read the documentation here for more details about copying ssh id.

Also, refer to here for details of setting up a config file for alias of ssh servers.

Trasnfer files

Assuming we are copying a file from a local machine to the server: scp -P *port* path/to/local/file username@ip:path/to/be/copied/to scp is the copy command to transfer files from server -P selects the port

If the files have already been copied but local files are a more updated version, then you can use rsync instead so that only the changes will be updated.

When transferring a directory containg many small files, it is best to tar the file first before moving. Details are here and here. By doing so, the efficiency is improved as tarring and transferring can be done simultaneously.

An alternative to scp is sshf, which can be used to set up remote directory as a mounted local directory. The command is also easy to use, just create a new directory and sshfs user@server.com:/remote/dir /home/user/local/directory. Note that ssh alias will not work here. All other commands such as mv, cp, tar can be used just like local commands. The downside is perhaps that root authority is required for all write access unless additionally set up.

Use tmux

It is best to use tmux instead of directly working on the terminal. The benefits include continuous session even when the connection has stopped and multiple windows. Refer to here for a list of commands

However, there are also some unintuitive parts such as the scrolling of the tmux terminal. Overall I think it still improves productivity.

Install software

It is likely that you will not have the admin authority on your server. If you do, you can safely ignore this section and just work on the server as you do on your local machine. If you do not, there will be some detours you need to make to install the software because you may not be allowed to install software by using sudo.

Install with pip

pip is a package management system used to install and manage software packages written in Python (from wikipedia pip page). Often Ubuntu’s default pip is when pip command is run is python2’s pip, unless you have set up a virtual environment for python3. pip3, the python3 version’s pip, may not always be installed. Since python2 will be deprecated in 2020, many software now requires installation to be done with pip3.

To install pip3 without sudo account, as of the time of writing, you can first download this file, then install pip by running python3 get-pip.py --user in the same directory as the directory of the downloaded file to install pip3.

After pip3 is installed, follow the instruction of pip3 installation. An example usage for instaslling deepbinner is pip3 install ./Deepbinner --user. Note that you may need to add --user yourself to ensure the installation can proceed.

Use software with source code and make

A software can still be used even it is not available on PyPI. Simply download the source code and use make to compile the software. Optionally the source code direcetory (that contains the executable file) can be added to PATH so that it can be run in other directories as well.

Refer to here for how to build software from sources.

Command to open GUI

Provided that you have activated X-server, using these commands will open some of the useful GUI provided on a Ubuntu machine.

File management

nautilus will open the file manager GUI. This can be a more convenient tool to look at the files than cd and ls repeatedly in terminal.

System monitor

gnome-system-monitor Command line alternatives are top and htop, which show usage of all individual users.

User management

sudo su to enter root user su user_name to switch to any user

Will be updated


Personalizing medicine