How to enable SSH for a specific user account using a public key instead of a password

Post Reply
User avatar
isscbta
Team Member
Posts: 130
Joined: Mon Jul 19, 2021 1:41 am
Has thanked: 16 times
Been thanked: 3 times

Before embarking on the process, it's important to ensure that you have correctly configured SSH access within the myVesta control panel. Follow these detailed steps to make the necessary changes:

Log in to your myVesta control panel and navigate to the USER/EDIT/SSH access section.

Under the SSH access settings, ensure that you have selected 'bash' as the shell for your user account. This setting is crucial for SSH functionality and ensures that you have the proper shell environment for secure access.

Now, let's proceed with configuring SSH access for your specific user account and enabling public key authentication:

Open your terminal and establish an SSH connection as the root user. This will grant you administrative privileges to perform the necessary actions:

Code: Select all

ssh root@your_server_ip
Replace "your_server_ip" with the actual IP address or hostname of your server.

After successfully connecting to your server, execute the following commands to set up SSH access with public key authentication. Replace "test" with the actual username for which you want to enable SSH access:

Code: Select all

USER='test'
cd /home/$USER
mkdir .ssh
chown $USER:$USER .ssh
chmod 0700 .ssh
cd .ssh
touch authorized_keys
chown $USER:$USER authorized_keys
chmod 0600 authorized_keys
These commands create a hidden .ssh directory in the user's home directory, set the appropriate ownership and permissions, and create the authorized_keys file where you'll store your public key.

Now, it's time to add your public key to the authorized_keys file. You can use a text editor to achieve this. In this example, we'll use the mcedit text editor, but you can use your preferred text editor:

Code: Select all

mcedit /home/$USER/.ssh/authorized_keys
This command will open the authorized_keys file for editing. Simply paste your public SSH key into this file and save the changes.

By following these steps, you have successfully configured SSH access for a specific user account using a public key instead of a password. This enhances security and simplifies the authentication process when connecting to your server.
Post Reply