SSH (Secure Shell Protocol)
add user and grant privileges
adduser username
sudo usermod -a -G sudo username
Enable SSH service in Ubuntu
sudo apt-get install openssh-server
sudo service ssh status
# change settings (e.g., the listening port, and root login permission)
sudo vim /etc/ssh/sshd_config
Enable SSH service in Windows
# 1. Install OpenSSH Server in Settings > Apps > Apps & features > Optional features > Add a feature
# 1.1 PowerShell# Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
# 2. open PowerShell
Start-Service sshd
# startup options
Set-Service -Name sshd -Startuptype 'Automatic'
# Firewall
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
To use SSH to communicate with GitLab, you need:
The OpenSSH client, which comes pre-installed on GNU/Linux, macOS, and Windows 10.
SSH version 6.5 or later. Earlier versions used an MD5 signature, which is not secure.
To view the version of SSH installed on your system, run ssh -V
SSH key
- ED25519
- ED25519_SK
- ECDSA_SK
- RSA
- DSA
- ECDSA
Generate an SSH key pair
- Run
ssh-keygen -t
followed by the key type and an optional comment. This comment is included in the .pub file that’s created
For example, for ED25519:
ssh-keygen -t ed25519 -C "<comment>"
For 2048-bit RSA:
ssh-keygen -t rsa -b 2048 -C "<comment>"
- Press
Enter
. Output similar to the following is displayed:
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/user/.ssh/id_ed25519):
Adding SSH key to the ssh-agent
# start the ssh-agent in the background
$ eval "$(ssh-agent -s)"
> Agent pid 59566
$ ssh-add ~/.ssh/id_ed25519
Configure SSH to point to a different directory
- Open a terminal and run this command:
eval $(ssh-agent -s)
ssh-add <directory to private SSH key>
- Save these settings in the
~/.ssh/config
file. For example:
# GitLab.com
Host gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitlab_com_rsa
# Private GitLab instance
Host gitlab.company.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/example_com_rsa
Copy ssh keys
macOS
tr -d '\n' < ~/.ssh/id_ed25519.pub | pbcopy
Linux (requires the xclip package)
xclip -sel clip < ~/.ssh/id_ed25519.pub
Git Bash on Windows
cat ~/.ssh/id_ed25519.pub | clip
In Server that you want to login
# 1. login to the serve using your username & password for the first time
cd ~
mkdir .ssh
vim authorized_keys
# 2. paste your public key in the file
# exit & re-login using publickey method
how to use linux screen
# screen [-opts] [cmd [args]]
screen --version
# Screen version 4.09.00 (GNU) 30-Jan-22
# Ctrl+a c Create a new window (with shell).
# Ctrl+a " List all windows.
# Ctrl+a 0 Switch to window 0 (by number).
# Ctrl+a A Rename the current window.
# Ctrl+a S Split current region horizontally into two regions.
# Ctrl+a | Split current region vertically into two regions.
# Ctrl+a tab Switch the input focus to the next region.
# Ctrl+a Ctrl+a Toggle between the current and previous windows
# Ctrl+a Q Close all regions but the current one.
# Ctrl+a X Close the current region.