LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-26-2008, 07:12 PM   #1
theunixwizard
Member
 
Registered: Feb 2008
Distribution: Ubuntu,Fedora,PC-BSD,FreeBSD
Posts: 116

Rep: Reputation: 15
Remote Logging into root


I was wondering how to configure my machine so that I can login
thru something like putty or SSH. Is it possible to configure it so I can
pass commands thru bash. Since my machine is multi-user would it matter if somebody is logged into their account as long as it isn't mine. Since I am root is it wise to log into my root account or my unprivileged account and then if I have to do administrative work use sudo
 
Old 06-26-2008, 08:19 PM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
You should never directly log into a machine via the root account, as there is a possibility that the root credentials can be sniffed. This is even true of older implementations of SSH (which you might unknowingly use, if the client and or server is misconfigured).

You should be using sudo whenever possible, both remotely and locally.

As for multiple users logged into the machine at once, that is no problem at all. It is what Unix operating systems were designed for from the start.

Enabling SSH would vary depending on which OS/distro we are actually talking about here (I see you use Linux as well as BSD).
 
Old 06-26-2008, 08:22 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Well, the ssh pkg comes a std on Linux, so its prob already installed.
Just turn off remote logins for root and instead login as yourself, then use sudo or 'su -' to get to root.

in your /etc/ssh/sshd_config file

Protocol 2
PermitRootLogin no

Only use root acct for tasks that require root privs. Do all normal work as your unpriv user acct.
Remote or local logins are effectively the same for each user, so you don't need to differentiate them.
 
Old 06-26-2008, 08:40 PM   #4
theunixwizard
Member
 
Registered: Feb 2008
Distribution: Ubuntu,Fedora,PC-BSD,FreeBSD
Posts: 116

Original Poster
Rep: Reputation: 15
Remote logging into root

I think that I will use my Linux installation for this(I might try BSD later). I kinda knewnot to log into my root account but I am a noob when it comes to remote login. I knew of Linux's Multitasking abilities but I was wondering if there would be a noticeable speed loss for the user at the machine as well as the one using remote login. I gather that it should be no problem setting up SSH, I was wondering if anybody had any tips or tricks to help me

Thanks for helping a idiot(me)

John
 
Old 06-26-2008, 08:43 PM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
I'd recommend using public key authentication.

First read through the manpages for sshd and sshd_config.
Also read through the /etc/sshd_config file. It should be well commented explaining which settings you want:

Code:
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
For a secure ssh setup check these setting for public key authentication:
Code:
sshd_config:
Protocol 2

PermitRootLogin no

UsePAM yes

PubkeyAuthentication yes

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no

# Change to no to disable s/key passwords
ChallengeResponseAuthentication no

AllowUsers username1 username2 etc...
Some people also change the default port number. This can reduce the noise from script kiddie brute force attacks.
The "AllowUsers" list will deny all other users including system users.

Make sure the $HOME and $HOME/.ssh/ directories are not world readable (including users added using setfacl). This is true for the public keys as well.

Use a good ssh passphrase. You can add a "from=" entry to the public key on the server. That way if you lost your keys, a hacker couldn't use them unless they also spoofed your IP address. However this will only work if you give a subnet range, or have a fixed IP address. The sshd manpage has more info on this field. Using a good passphrase should protect the key as well.

Consider using ssh-agent and ssh-add before logging in. This way you only need to enter the passphrase once per session:

Code:
eval $(ssh-agent)
ssh-add
If you use putty from Windows on the client machine, their keygen.exe program lets you load in your key. An openssh pubic key is displayed near the top of the window. So you can use public key authentication using windows as well. Although, I would install Cygwin/X instead. Using Cygwin/X, you would configure the same openssh client and you could run graphical programs remotely as well.
 
Old 06-26-2008, 09:56 PM   #6
theunixwizard
Member
 
Registered: Feb 2008
Distribution: Ubuntu,Fedora,PC-BSD,FreeBSD
Posts: 116

Original Poster
Rep: Reputation: 15
Remote logging into root

I have reviewed all of your suggestions and I was lost from the moment
I read the first sentence. I am using ubuntu as the SSH Server and
I want it to be secure as possible.Is there is a way to do this simply
and still have security?
 
Old 06-26-2008, 10:24 PM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
"Wiz," it will be necessary for you move beyond "lost" and learn some new stuff about how to do this... but, really, it's not that hard and the Internet is actually stuffed with good information about it.

Basically, here's some "common-sense food for thought," that ought to help you move in the right direction...

First of all, you want to make sure that the only way to log in to the box is through ssh, a "secure shell" that encrypts traffic.

Next, you really don't want people being able to log on to 'root' directly... so you configure ssh never to allow direct logins to that account.

Next, you don't want "just anyone" plinking away at your system, firing username/password combinations at it... even through ssh. You want them to have to identify themselves in a way that is basically un-forgeable... and that's called "digital certificates." (Think of 'em as identification-badges.)

Also, since ssh will fall-back to easier-and-easier authentication mechanisms by-default, you'll set things up so that it won't actually ever fall-back to "password authentication."

The nice thing about digital certificates is the very same nice-thing that we say for badges: if someone gets fired, say, their digital certificate can be made to drop-dead. Conversely, unless someone "gets hired," he never gets a certificate... and therefore he simply can't get anywhere-near the point of actually logging in.
 
Old 06-27-2008, 05:24 AM   #8
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
The lines I included where the ones that I changed in the default /etc/ssh/sshd_config file. Although the "UsePam=Yes" line is the same, the other changes disable user/password authentication, so PAM is just used to check that the account exists and enforces limits on the user.

You create a key pair on the client machine using the "ssh-keygen" program. This creates a public and a private key in ~/.ssh/. If you generate an RSA key pair they will be called ~/.ssh/rsa_id and ~/.ssh_id.pub. The ~/.ssh_id.pub is the public key.

Here is a sample public key (id_rsa.pub) that I generated for this post. The ssh-keygen program asked for a keyphrase which I included as well. This keyphrase will scramble the private key so that it can only be unlocked and useable after entering the keyphrase. You will be prompted for it at the client when you use ssh to connect to any server.

Code:
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAynpqS6uWZSM7G2+Rx+02YJ+mfrSWkqbMlHYllfaRCohagv/y+FX7MFQfV0J4R0dwGcAua15jn0Xmk7yA+QAN0PczjdL/PHQwpOtNLoLm2w2rXkm5EVEtJzLzcrfA71VJE4B9v2VDTA2cABJ16l0wX8OcBJM1Yk8PP5/x2nBowyDCdPFcgGjnTzSW/Gu4nuwOQbt2/Y8Mk7YIHPO+PrXUJidx07r30/hwtqp/eIbtSvUNn/bHJnApluAjoqWpadXOYM8L363FmbF/Eo7KeaGfVpBR/ELHFTalLtk2w1HBPN3YKFDS6JRO3qU7rDJHHqerFmRZinqF6z9zPD+yqMleTw== jschiwal@hpamd64
In my case I would log into a server named "hpmedia". So I need to log into hpmedia and add this key (id_rsa.pub) to the authorized keys file:
Code:
cat >>.ssh/authorized_keys id_rsa.pub
Notice that at the end of the public key is the name of the user and the hostname of the client.

Next I would edit the /etc/ssh/sshd_config file on the server (hpmedia) and make the changes I listed in my last post. Then I would restart the sshd daemon on the server.

---

If your client is a windows machine, I would recommend installing Cygwin/X. This will install an X server and a bare bones unix like system that can run Linux scripts, console programs and the fvwm2 windows manager. Using this you can run gui programs remotely on the server and have them displayed on your local X server display.

Another option is to use putty. Putty has a puttygen.exe ( I got the name wrong in the last message ) program. You can use this program to run a keypair in putty. The files will have a .ppk extension. You can use this program to generate a private and public key pair in windows and then save the key. If you already have a key pair generated you can click on "Load Private Key". There is a line at the top of the dialog that says:
Public key for pasting into OpenSSH authorized_keys file:

The public key is displayed. Highlight and copy the public key and save it into a scrap file. Add that key to the end of the ~/.ssh/authorized_keys file on the server.

---

Now when you log in from your client (such as a laptop) to the server (the Ubuntu server), The client (laptop) will use it's private key (~/.ssh/id_rsa) to send a message to the server. The server will only be able to decode this message by using the public key that you added to the ~/.ssh/authorized_keys file. Without the public key, the private key won't make any sense and the authentication will fail.

---

If you use a passphrase ( which I highly recommend ) you will need to enter the passphrase at the client to unlock the private key before using it. It can be a pain to do this every time you log in to a remote server. You can do this once using two programs, ssh-agent and ssh-add. You run this at the console before logging in, like this:

Code:
eval $(ssh-agent)
ssh-add
You will be prompted to the passphrase. It will be held securely in memory and used to unlock the private key everytime you log into an ssh server.

Suppose someone steals the files from your laptop! They now have your key pair (very bad). But because it is passphrase protected, they can't unlock the private key without your passphrase. The only way to unlock the private key is by brute force, trying different passphrases.

Good Luck!

Last edited by jschiwal; 07-02-2008 at 02:31 PM. Reason: fixed typo
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
logging into remote machine with root id tuxfood Linux - General 2 08-08-2005 07:15 AM
remote logging linuxboy69 Linux - Software 3 02-25-2004 04:30 PM
Remote logging? Inexactitude Linux - Networking 5 11-23-2003 02:02 PM
using red-carpet without logging out and logging as root. packman Linux - Software 1 12-09-2002 02:55 AM
Remote logging sts_cat Linux - General 2 04-30-2002 08:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration