Current Size:
Chakra BreakPoints
base0px
sm480px
md768px
lg992px
xl1280px
2xl1536px
Current Height:Width
widthpx
heightpx

Subjects

SSH Catch

Date Created: 2022/02/11

Last Update: 2023/03/18

#git #reference

SSH Reference

  • creating keys
  • common errors
  • ssh between machines
  • handling ssh with git and different accounts

ssh into remote server

ssh <remote-username>@<remote_domain/ip>

Examples

If a ssh key pair is found a new session will start. If not and the machine allows ssh access via user name and password a prompt for password will occur.

Move File or Directories between Machines

scp <source> <destination>

Files

scp /path/to/file username@:host/path/to/destination
scp username@host:/path/to/file /path/to/destination

Example

scp [email protected]:~/foo ~/foo

Dir

scp -r /path/to/dir username@:host/path/to/destination
scp -r username@host:/path/to/dir /path/to/destination

Set-Up ssh Access

Generate Key

ssh-keygen -t rsa

Github Example

ssh-keygen -t ed25519 -C "[email protected]"

For a single service use the default file .ssh/id_rsa but for multiple services follow the steps below.

Generate SSH Key and Add It to Remote Machine

ssh-copy-id -i ~/.ssh/<name-public-key>.pub <server_user_name>@<ip_add_server>

Setting Up Unique SSH for Multiple Services

Make a config

touch ~/.ssh/config

Example config

config

# contents of $HOME/.ssh/config
Host github.com
IdentityFile ~/.ssh/github.key
Host gitlab.com
IdentityFile ~/.ssh/gitlab.key

Now when ssh-keygen -t rsa asks for a file specify the file associated with the domain or service

Example key gen

Generating public/private ed25519 key pair.
Enter file in which to save the key (/Users/<foo>/.ssh/id_ed25519): github.key
ssh-keygen -t ed25519 -C <github-email>

πŸ’‘ note: if the file does not show up in .ssh/ using the full path should correct

Add Host to known Hosts

ssh auth Error

"The authenticity of host '216.128.129.16 (216.128.129.16)' can't be established.
ED25519 key fingerprint is SHA256:nnzspBxbguoVHYiPiPEL6smGCfyE2KRSMLmayeaH3Mw.
This key is not known by any other names"
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
ssh-keyscan -H <ip.address> >> ~/.ssh/known_hosts

Add to Service

πŸ”₯ make sure to use the .pub extension as this is where our public key is stored

pbcopy < ~/.ssh/github.key.pub

Add this to the services we want to Authorize.

Testing and Troubleshooting Connections

Test ssh connection

Verbose tst

We can also test a specific host from out ~/.ssh/config

Use with Github, BitBucket, Gitlab etc

Cloning a new project

Clone repos with the host name declared in ssh config πŸ‘‡

git clone git@work:username/my-work-project.git
git clone git@personal:username/my-personal-project.git

For reference, this is the default behavior

git clone [email protected]:username/my-work-project.git
git clone [email protected]:username/my-personal-project.git

Updating and existing repo

To update and existing repo to push to a specific github account/profile. Navigate to the project .git/config and add the Host from .ssh/config as the host in the ssh url.

Example

.git/config

...
[remote "origin"]
url = git@work-profile:username/work-project-two.git
...

SSH Between Two Mac on LAN

Common Friction Points

You can try the following but it can fail Full Disk Access privileges. error.

sudo systemsetup -setremotelogin on

If πŸ‘†that doesn't work try πŸ‘‡

## Enabling SSH
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

to turn remote access off as a security best practice.

## Disabling SSH
sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist

Check Status

# To check if is on or off
sudo systemsetup -getremotelogin

Reference

Set up ssh key auth between machines

More Notes

All Notes
HomeProjects

Links

Home Articles Notes Projects About Style Guide Site Credits

Contact

Β [email protected]

Location

🌎 Earth