Skip to main content

How to enable and configure root user’s SSH login on Azure Ubuntu

If you are using Microsoft’s Azure Ubuntu, you may find that the default normal user azureuser has some limitations, such as not being able to use ports below 1024 when setting up SSH Server2Client (S2C) port mapping. At this time, you may want to use the root user to gain higher privileges and flexibility. However, Azure Ubuntu does not directly support root user login, you need to do some configuration to achieve it. This article will introduce how to enable and configure root user’s SSH login on Azure Ubuntu, and how to use root user’s SSH public key login method.

Enable root user’s password login

First, we need to set a password for the root user, and then modify some configuration files to allow root user’s password login. The specific steps are as follows:

  • Log in to the system as a normal user azureuser, open the terminal, and enter the following command to set a password for the root user:
sudo passwd root
  • Enter your azureuser password, then enter the root password you want to set, and confirm again.
  • Enter the following command to edit the SSH configuration file:
sudo nano /etc/ssh/sshd_config
  • Find the following parameter and change it to yes:
PermitRootLogin yes
  • Save and exit the SSH configuration file, and restart the SSH service:
sudo service sshd restart
  • Now, in principle, you can use the root password to log in to the root user. You can use the following command:
ssh root@your_server_ip

Configure root user’s SSH public key login

However, for security reasons, Azure Ubuntu prohibits password login and can only use public key login. This means that you need to generate a pair of SSH keys, and then upload the public key to the server, before you can use the private key to log in. The advantage of doing this is that you don’t need to remember or enter a password, and you don’t have to worry about the password being cracked or leaked. The method is as follows:

  • Generate a new key pair in the SSH client, such as Bitvise SSH Client -->Client Key Manager–>Generate New.
  • Export the Public Key file of the new key pair, select OpenSSH Format, such as a.pub
  • Upload this file to ubuntu, such as /home/azueruser/a.pub
  • Log in to the system as a normal user azureuser, open the terminal, and enter the following command to elevate to root:
sudo -i
  • Copy the public key file a.pub to the /root/.ssh/ directory and rename it to authorized_keys. You can use the following command:
cp /home/azureuser/a.pub /root/.ssh/authorized_keys
  • Edit the SSH configuration file, command nano /etc/ssh/sshd_config, and make sure the following parameters are enabled (no # sign):
RSAAuthentication yes
PubkeyAuthentication yes
  • If you want to disable root user’s password login, you can change the following parameter to no:
PasswordAuthentication no
  • Save the SSH configuration file and restart the SSH service. You can use the following command:
service sshd restart
  • Now, you can use the private key file (id_rsa) to log in to the root user. You can use the following command:
ssh -i id_rsa root@your_server_ip

Use root user’s port mapping

After logging in as the root user, you can also use ports below 1024. You can set the port mapping you want according to your needs, such as:

ssh -i id_rsa -L 80:localhost:80 root@your_server_ip

This way, you can access the 80 port on the server in your local browser.

Summary

This article introduced how to enable and configure root user’s SSH login on Azure Ubuntu, and how to use root user’s SSH public key login method. This way, you can gain higher privileges and flexibility to meet your needs. Of course, using the root user also requires attention to security and responsibility, do not arbitrarily modify or delete important files or settings, to avoid unnecessary trouble.

Comments

Popular posts from this blog

How to Set Buffer Size for TCP Socket Programming in C++

TCP socket programming is a common way to communicate between different processes or machines over the network. However, one of the challenges of TCP socket programming is how to set the buffer size for sending and receiving data. The buffer size determines how much data can be stored in memory before it is transmitted or processed. If the buffer size is too small, the data may be fragmented or lost, resulting in poor performance or errors. If the buffer size is too large, the memory may be wasted or the data may be delayed, affecting the responsiveness or timeliness of the communication. In this blog post, I will explain how to set the buffer size for TCP socket programming in C++, and provide some examples of how to use the relevant functions and parameters. The buffer size for TCP socket programming in C++ can be set by using the setsockopt function, which allows the programmer to change the options for a socket. The setsockopt function has the following prototype: int setsockopt...

Example: A TCP Socket Echo Server in Python

Introduction TCP (Transmission Control Protocol) is one of the most widely used protocols in the Internet. It provides reliable, ordered, and error-checked delivery of data between applications running on different devices. A TCP socket is an endpoint of a TCP connection, which is identified by an IP address and a port number. A TCP socket can send and receive data to and from another TCP socket over the network. In this article, I will show you how to write a simple TCP socket echo server in Python, which is a program that listens for incoming connections from TCP socket clients, and echoes back whatever data it receives from them. This program can be useful for testing the functionality and performance of TCP sockets, as well as learning the basics of socket programming in Python. Requirements To write and run this program, you will need the following: - A computer with Python 3 installed. You can download Python 3 from [here]. - A text editor or an IDE (Integrated Development Enviro...

How to Fix TCP Socket Error Code 10061 in C++, Python, and Java

If you are interested in my TCP socket software development, consulting or training services, please feel free to contact me.   contact email: tcpfast@gmail.com TCP  socket error code 10061 is a common network connection error that indicates that the target server refused the connection request. This usually happens when you try to connect to a service that is not running on the target host, or when your network firewall or antivirus software blocks the port communication. In this blog post, I will explain the possible causes of this error and how to fix it in different programming languages, such as C++, Python, and Java. Possible Causes of TCP Socket Error Code 10061 There are several possible reasons why you may encounter TCP error code 10061 when you try to establish a TCP connection with a server. Some of the most common ones are: - You are using the wrong port number or protocol type (TCP or UDP) to connect to the server. For example, if the server is listening on p...