转自:https://www.runoob.com/w3cnote/set-ssh-login-key.html

我们一般使用 PuTTY 等 SSH 客户端来远程管理 Linux 服务器。但是,一般的密码方式登录,容易有密码被暴力破解的问题。所以,一般我们会将 SSH 的端口设置为默认的 22 以外的端口,或者禁用 root 账户登录。其实,有一个更好的办法来保证安全,而且让你可以放心地用 root 账户从远程登录——那就是通过密钥方式登录。

密钥形式登录的原理是:利用密钥生成器制作一对密钥——一只公钥和一只私钥。将公钥添加到服务器的某个账户上,然后在客户端利用私钥即可完成认证并登录。这样一来,没有私钥,任何人都无法通过 SSH 暴力破解你的密码来远程登录到系统。此外,如果将公钥复制到其他账户甚至主机,利用私钥也可以登录。

下面来讲解如何在 Linux 服务器上制作密钥对,将公钥添加给账户,设置 SSH,最后通过客户端登录。

1. 制作密钥对

首先在服务器上制作密钥对。首先用密码登录到你打算使用密钥登录的账户,然后执行以下命令:

[root@host ~]$ ssh-keygen  <== 建立密钥对  #或生成pem:ssh-keygen -t rsa -f my.pem -C "your@email.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): <==  Enter
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): <== 输入密钥锁码,或直接按 Enter 留空
Enter same passphrase again: <== 再输入一遍密钥锁码
Your identification has been saved in /root/.ssh/id_rsa. <== 私钥
Your public key has been saved in /root/.ssh/id_rsa.pub. <== 公钥
The key fingerprint is:
0f:d3:e7:1a:1c:bd:5c:03:f1:19:f1:22:df:9b:cc:08 root@host

密钥锁码在使用私钥时必须输入,这样就可以保护私钥不被盗用。当然,也可以留空,实现无密码登录。

现在,在 root 用户的家目录中生成了一个 .ssh 的隐藏目录,内含两个密钥文件。id_rsa 为私钥,id_rsa.pub 为公钥。

2. 在服务器上安装公钥

键入以下命令,在服务器上安装公钥:

[root@host ~]$ cd .ssh
[root@host .ssh]$ cat id_rsa.pub >> authorized_keys

如此便完成了公钥的安装。为了确保连接成功,请保证以下文件权限正确:

[root@host .ssh]$ chmod 600 authorized_keys
[root@host .ssh]$ chmod 700 ~/.ssh

3. 设置 SSH,打开密钥登录功能

编辑 /etc/ssh/sshd_config 文件,进行如下设置:

RSAAuthentication yes
PubkeyAuthentication yes

另外,请留意 root 用户能否通过 SSH 登录:

PermitRootLogin yes

当你完成全部设置,并以密钥方式登录成功后,再禁用密码登录:

PasswordAuthentication no

最后,重启 SSH 服务:

[root@host .ssh]$ service sshd restart

4. 将私钥下载到客户端,然后转换为 PuTTY 能使用的格式

使用 WinSCP、SFTP 等工具将私钥文件 id_rsa 下载到客户端机器上。然后打开 PuTTYGen,单击 Actions 中的 Load 按钮,载入你刚才下载到的私钥文件。如果你刚才设置了密钥锁码,这时则需要输入。

载入成功后,PuTTYGen 会显示密钥相关的信息。在 Key comment 中键入对密钥的说明信息,然后单击 Save private key 按钮即可将私钥文件存放为 PuTTY 能使用的格式。

今后,当你使用 PuTTY 登录时,可以在左侧的 Connection -> SSH -> Auth 中的 Private key file for authentication: 处选择你的私钥文件,然后即可登录了,过程中只需输入密钥锁码即可。

I needed to run LSI MegaRaid Storage Manager (vivaldiframework) for my LSI 9260-8i SAS card in my Ubuntu Desktop. Ubuntu is based on Debian so this may also work to get LSI MegaRaid Storage Manager on Debian as well, but I have not yet tried it yet. It took some work but I go it to install so I thought I would tell you how I did it. It is assumed that in the following, when editing a file you are doing it with superuser rights such as opening the files from the comand prompt with "sudo nano /path/to/file/file" or "sudo vi /path/to/file/file"

I found that you need to have a GUI installed (though the install can be done completely by ssh.

root account:

If the root account has not been enabled, it will need to be enabled and have a pasword set

sudo passwd root

sudo passwd -u root

Install prerequisites:

sudo apt-get install alien libstdc++5  rcconf

You also need to install at least Java 7, I am using Java8. I followed the procedure found at: http://www.ubuntugeek.com/how-to-install-oracle-java-7-in-ubuntu-12-04.html and just changed java7 in the command line to java8

 

You need to download the Linux  build from LSI (http://www.lsi.com/support/pages/download-results.aspx?component=Storage+Component&productfamily=RAID+Controllers&productcode=P00066&assettype=Management+Software+and+Tools&productname=MegaRAID+SAS+9260-8i). I initially tried the latest but had some problems with it. It could very well have been a fluk but I just went back to the 13.11.01.00 version that worked just fine.

mkdir ~/LSI

cp 13.11.01.00_Linux_x64_MSM.gz ~/LSI/

cd ~/LSI/

tar xzvf 13.11.01.00_Linux_x64_MSM.gz

cd disk

sudo alien --scripts *.rpm

install deb packages

sudo dpkg --install lib-utils2_1.00-6_all.deb

sudo dpkg --install megaraid-storage-manager_13.11.01-1_all.deb

edit /etc/init.d/vivaldiframeworkd and replace the line

for ((i=0, i < 20, i++))

with

for i in `seq 0 19`

edit "/usr/local/MegaRAID Storage Manager/Framework/startupui.sh" and replace

LD_LIBRARY_PATH=`pwd`:/opt/lsi/Apache:/opt/lsi/Pegasus:/opt/lsi/openssl;export LD_LIBRARY_PATH

with

LD_LIBRARY_PATH=`pwd`:/opt/lsi/Pegasus:/usr/sbin/openssl;export LD_LIBRARY_PATH

configure the service to start automatically:

sudo rcconf

arrow down to the vivaldiframeworkd, if it does not have an "*" in it , hit the space bar to select it, then hit enter or tab to OK

 

Restart the vivaldiframeworkd service:

sudo /etc/init.d/vivaldiframeworkd restart

if you want to use the Graphical desktop installed on you box you can access the GUI with

cd "/usr/local/MegaRAID Storage Manager"

./startupui.sh

 

gcc 4.8 安装

curl -Lks http://www.hop5.in/yum/el6/hop5.repo > /etc/yum.repos.d/hop5.repo
yum install gcc gcc-g++
gcc --version

gcc 4.9 安装

yum install centos-release-scl
yum install devtoolset-3-toolchain
scl enable devtoolset-3 bash
gcc --version

gcc 5.2 安装

yum install centos-release-scl
yum install devtoolset-4-toolchain
scl enable devtoolset-4 bash
gcc --version

scl enable devtoolset-3 bash只是临时覆盖系统原有的GCC引用,如果想永久覆盖,可在root/.bashrc文件中添加source /opt/rh/devtoolset-3/enable

文章来自参考:https://www.dwhd.org/20160724_085212.html

gcc 4.8 安装

curl -Lks http://www.hop5.in/yum/el6/hop5.repo > /etc/yum.repos.d/hop5.repo
yum install gcc gcc-g++
gcc --version

gcc 4.9 安装

yum install centos-release-scl
yum install devtoolset-3-toolchain
scl enable devtoolset-3 bash
gcc --version

gcc 5.2 安装

yum install centos-release-scl
yum install devtoolset-4-toolchain
scl enable devtoolset-4 bash
gcc --version

scl enable devtoolset-3 bash只是临时覆盖系统原有的GCC引用,如果想永久覆盖,可在root/.bashrc文件中添加source /opt/rh/devtoolset-3/enable

文章来自参考:https://www.dwhd.org/20160724_085212.html