General Kelly was also questioned about Mr. Trump’s suggestion that he might revive a dormant registry program for visitors from countries with active terrorist groups — a program critics say unfairly targets Muslims.
Kris W. Kobach, the Kansas secretary of state and a member of Mr. Trump’s transition team, was photographed in November with a document of first-year proposals that included, under the rubric “Bar the Entry of Potential Terrorists,” a proposal to reintroduce the registry program.
Senator Gary Peters, Democrat of Michigan, asked General Kelly if he supported the program.
“I don’t agree with registering people based on ethnicity or religion,” General Kelly replied.
Senator Rand Paul, Republican of Kentucky and a longtime critic of government surveillance programs, asked General Kelly if he supported the bulk collection of data on Americans.
“I’m not for the mass collection of data,” General Kelly said. “I go the other way.”
Lawmakers did not broach the subject of Mr. Trump’s proposal to deport millions of undocumented immigrants once he takes office, although Senator Kamala Harris of California, a newly elected Democrat and a former state attorney general, asked about the fate of undocumented immigrants who were brought to the United States as children. General Kelly said he would enforce the law.
If confirmed, General Kelly will become the fifth person and the first former military officer to lead the Department of Homeland Security, which is responsible for protecting the country from terrorist attacks and managing the nation’s response to disasters.
General Kelly was introduced to the homeland security panel by Robert M. Gates, a secretary of defense under President Obama and George W. Bush, and by Mr. McCain.
Mr. Gates, who was General Kelly’s boss during a tour at the Pentagon, called him a “straight-talking, candid, courageous leader who will say exactly what he thinks.” Mr. Gates described him as a reliable, competent leader, capable of managing a complex, multipart operation.
“To put it quite simply, he is one of the finest people I have ever known,” Mr. Gates said. “I would trust him with my life.”
As Senator Ron Johnson, Republican of Wisconsin and chairman of the Homeland Security Committee, opened the confirmation hearing, he called General Kelly the most qualified person to lead the department. Senator Claire McCaskill of Missouri, the top Democrat on the panel, also praised the general and later wrote on Twitter that he was a “good choice.”
The hearing was remarkable for its subdued tone. Even members of the protest group Code Pink listened quietly in their bright pink capes, mere hours after they disrupted the confirmation hearing for Senator Jeff Sessions of Alabama, Mr. Trump’s nominee for attorney general.
Most of the lawmakers’ questions focused on General Kelly’s plans to combat terrorism, defend against computer breaches and enhance border security, including how to protect the largely unsecured northern border with Canada.
If confirmed, General Kelly will take over a department with a budget of over $40 billion and more than 240,000 workers. The agency is responsible for border security, immigration control, responding to natural disasters, cybersecurity and screening passengers at airports, among other duties.
General Kelly called Jeh Johnson, the current sectary of homeland security, a friend, and said he had worked closely with Customs and Border Protection and the Coast Guard while he was in charge of the military’s Southern Command. He often praised the two agencies in testimony before Congress.
General Kelly will face a number of challenges if he is confirmed. Despite improvements in recent years, the department continues to have persistent management problems, and employee morale is consistently low compared with other federal agencies.