Showing posts with label SSH. Show all posts
Showing posts with label SSH. Show all posts

20 May 2024

How to Set up SSH Access to Github


==================================
How to Set up SSH Access to Github
==================================


1. Generate both public key and private key
-------------------------------------------

On your machine, change directory to ~/.ssh

$ ssh-keygen -t ed25519

You have got two files - 'id_ed25519' and 'id_ed25519.pub'. One is the public key, the other the private key. The public key file name has '.pub' at the end. The private key file has not.

2. Put public key on Github
---------------------------

Open github website. Log in. Click the Profile icon at the top right hand side corner > Settings > 'Access | SSH and GPG keys' > 'SSH keys | New SSH key'. Paste your public key there.

3. Copy your repository SSH address
-----------------------------------

Click profile icon > 'Your repositories'. Click one of the repositories > Code > SSH. Click the copy icon.

4. git clone
------------

Go back to your machine. You can git clone already.

$ git clone <Github SSH address> # (without <>)

5. git remote add origin
------------------------

Change directory to the branch. Append the SSH address to the following command, and run the command

$ git remote add origin <Github SSH address> # (without <>)

Change directory to .git/ under the branch directory.

Open ~/.git/config, you would see 

[remote "origin"]
    url = git@github.com:<githubUserName>/<branch>.git

6. Delete branch https address
------------------------------

If you used to use password/token access to Github, then there must be an http url in the config file. Remove it, otherwise Github will still ask for your password/token.

7. git pull or push
-------------------

You can now git pull and git push now.

$ git pull origin main

$ git push origin main

06 September 2021

SSH client command line

SSH client command line

ssh -p 22 (user)@127.0.0.1


sshd: no hostkeys available -- exiting

sshd: no hostkeys available -- exiting

https://www.garron.me/en/linux/sshd-no-hostkeys-available-exiting.html

I only needed to run

ssh-keygen -A

In the /etc/ssh/ folder, and the start the server

/etc/init.d/ssh start


What if ssh would not start?

What if ssh would not start?

 
This issue is caused by a bad configuration of /etc/ssh/sshd_config file. When the service try to launch it does not recognize every fields of this configuration file. In order to solve this issue, you must use the tool

/usr/sbin/sshd -T

In case /etc/ssh/sshd_config was wrong, this would show wrong parameters with lines.

You must correct this issues and then restart the service:

/etc/init.d/ssh restart

How to install and configure SSH on Ubuntu

How to install and configure SSH on Ubuntu

https://help.ubuntu.com/community/SSH/OpenSSH/Configuring

 

28 February 2017

Using Public Keys for SSH Authentication

Using PuTTYgen

Set up SSH public key authentication



Generate Key Pair

If you do not have a key pair yet, start with generating new key pair.

Configure Server to Accept Public Key

Connect to your SSH server using WinSCP with the SSH protocol, using other means of authentication than public key, e.g. typically using password authentication.
Once logged in, configure your server to accept your public key. That varies with SSH server software being used. The most common SSH server is OpenSSH.

OpenSSH

  • Navigate into a .ssh subdirectory of your account home directory. You may need to enable showing hidden files to see the directory. If the directory does not exists, you need to create it first.
  • Once there, open a file authorized_keys for editing. Again you may have to create this file, if this is your first key.
  • Switch to the PuTTYgen window, select all of the text in the Public key for pasting into authorized_keys file box, and copy it to the clipboard (Ctrl+C). Then, switch back to the editor and insert the data into the open file, making sure it ends up all on one line. Save the file.
  • Ensure that your account home directory, your .ssh directory and file authorized_keys are not group-writable or world-writable. Recommended permissions for .ssh directory are 700. Recommended permissions for authorized_keys files are 600. Read more about changing permissions.

ssh.com

  • Save a public key file from PuTTYgen, and copy that into the .ssh2 subdirectory of your account home directory.
  • In the same subdirectory, edit (or create) a file called authorization. In this file you should put a line like Key mykey.pub, with mykey.pub replaced by the name of your key file.

Other SSH Servers

For other SSH server software, you should refer to the manual for that server.

Configure WinSCP Session

When configuring session, specify path to your private key on SSH > Authentication page of Advanced Site Settings dialog.
Alternatively, load the private key into Pageant.

22 February 2017

Restrict SFTP (SSH) users to home folder

https://bensmann.no/restrict-sftp-users-to-home-folder/

Here is a guide for setting up SFTP users who’s access is restricted to their home directory.
Add the following to the end of the /etc/ssh/sshd_config file:
Subsystem sftp internal-sftp

# This section must be placed at the very end of sshd_config
Match Group sftponly
    ChrootDirectory %h
    ForceCommand internal-sftp
    AllowTcpForwarding no
This means that all users in the ‘sftponly’ group will be chroot’d to their home directory, where they only will be able to run internal SFTP processes.
Now you can create the group sftponly by running the following command:
$ groupadd sftponly
Set a user’s group:
$ usermod steve -g sftponly
To deny SSH shell access, run the following command:
$ usermod steve -s /bin/false
And set the user’s home directory:
$ usermod steve -d /folder
Finally, you probably need to restart SSH
$ service ssh restart
The SSH part should now be in order, but you should make sure that file permissions also are correct. If the chroot environment is in a user’s home directory both /home and /home/username MUST be owned by root and should have permissions along the lines of 755 or 750.
In other words, every folder leading up to and including the home folder must be owned by root, otherwise you will get the following error after logging in:
Write failed: Broken pipe
Couldn't read packet: Connection reset by peer