In my project, I have to install some package remotely. If I have to login in debian, I say:
$ ssh root@remotehostname
root@remotehostname's password:
it logs in successfully.
I have login in ubuntu in directly using
$ root@remotehostname
root@remotehostname's password:
it is throw error message in
Permission denied, please try again.
How to solve this problem?
check the /etc/ssh/sshd_config
whether the configure PermitRootLogin yes
below # Authentication:
. If not yes
, it doesn't permit login as root.
you can change it to yes
.
Then, restart ssh service to apply the changes:
sudo service sshd restart
Ubuntu documentation says:
By default, the Root account password is locked in Ubuntu.
It also says:
Please keep in mind, a substantial number of Ubuntu users are new to Linux. There is a learning curve associated with any OS and many new users try to take shortcuts by enabling the root account, logging in as root, and changing ownership of system files.
It talks at length about why it's been done this way.
Enabling the root account:
sudo -i
To enable the Root account (i.e. set a password) use:
sudo passwd root
Use at your own risk!
Logging in to X as root may cause very serious trouble. If you believe you need a root account to perform a certain action, please consult the official support channels first, to make sure there is not a better alternative.
Do not enable the root account. Do not set a password for the root account.
A better way is to allow root login using public key authentication, not with password. The reasoning is explained in the Debian mailing list archives.
Open /etc/ssh/sshd_config
and check if PermitRootLogin
is set to yes
. If not, then set it to yes and restart ssh
with sudo service ssh restart
Create the .ssh
directory in root's home if it doesn't exist and make sure it has strict permissions:
sudo -i mkdir -p .ssh
sudo -i chmod 700 .ssh
Create a public/private key pair in the system you want to login from.
Copy your public key to your regular user account.
Append your public key to .ssh/authorized_keys
of root, and make sure the file has strict permissions:
cat id_rsa.pub | sudo -i tee -a .ssh/authorized_keys
sudo -i chmod 600 .ssh/authorized_keys
With this setup you should be able to login as root using your private key.
If you have previously enabled the root
account, make sure to disable it now:
sudo passwd -l root
You could set a password for root, but this is not recommended and could open a security risk. But if you have an user account on the target system that has sudo credentials, you could log in as user:
ssh user@remotehostname
user@remotehostname's password:
and then do what you want using sudo or get a root shell the recommended way:
user@remotehostname$ sudo su
Password:
root@remotehostname#
and then do your housekeeping. Instead of 'sudo su' you also could use 'sudo -i', which is equivalent, or 'sudo -s', that keeps the current environment.
See Ubuntu Sudo/Root documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With